Skip to content

Commit

Permalink
Do not use && and || in translated R expressions (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Cook committed Aug 31, 2019
1 parent 4a0d167 commit 35fba0f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions R/translations.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ translations_operators_binary_symbolic <- list(
)

translations_operators_binary_word <- list(
`and` = "&&",
`or` = "||",
`and` = "&",
`or` = "|",
`div` = "%/%",

# variants negated by prefixing "not " must come BEFORE their positive equivalents
Expand Down Expand Up @@ -226,15 +226,15 @@ translations_indirect_generic <- list(
# is equivalent to
# if (x IS NULL OR y IS NULL, (x IS NULL) = (y IS NULL), x = y)
eval(substitute(quote(
ifelse(is.na(x) || is.na(y), is.na(x) == is.na(y), x == y)
ifelse(is.na(x) | is.na(y), is.na(x) == is.na(y), x == y)
)))
},
`%<!=>%` = function(x, y) {
# x is distinct from y
# is equivalent to
# if (x IS NULL OR y IS NULL, x IS NULL != y IS NULL, x != y)
eval(substitute(quote(
ifelse(is.na(x) || is.na(y), is.na(x) != is.na(y), x != y)
ifelse(is.na(x) | is.na(y), is.na(x) != is.na(y), x != y)
)))
},
degrees = function(rad) {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-parse_query.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test_that("parse_query(tidy = TRUE) works on 'flights' example query", {
list(select = list(quote(origin), quote(dest), num_flts = quote(sum(!is.na(flight))),
dist = quote(round(mean(distance, na.rm = TRUE))), avg_delay = quote(round(mean(arr_delay,
na.rm = TRUE)))), from = list(quote(flights)), where = list(
str2lang("dplyr::between(distance, 200, 300) && !is.na(air_time)")), group_by = list(
str2lang("dplyr::between(distance, 200, 300) & !is.na(air_time)")), group_by = list(
quote(origin), quote(dest)), having = list(quote(num_flts >
5000)), order_by = list(str2lang("dplyr::desc(num_flts)"), str2lang("dplyr::desc(avg_delay)")),
limit = list(100L))
Expand All @@ -43,7 +43,7 @@ test_that("parse_query(tidy = FALSE) works on 'flights' example query", {
list(select = list(quote(origin), quote(dest), num_flts = quote(sum(!is.na(flight))),
dist = quote(round(mean(distance, na.rm = TRUE))), avg_delay = quote(round(mean(arr_delay,
na.rm = TRUE)))), from = list(quote(flights)), where = list(
quote((distance >= 200 & distance <= 300) && !is.na(air_time))), group_by = list(
quote((distance >= 200 & distance <= 300) & !is.na(air_time))), group_by = list(
quote(origin), quote(dest)), having = list(quote(num_flts >
5000)), order_by = structure(list(quote(num_flts), quote(avg_delay)), descreasing = c(TRUE,
TRUE)), limit = list(100L))
Expand Down

0 comments on commit 35fba0f

Please sign in to comment.