Skip to content

Commit

Permalink
Correct translations for T and F
Browse files Browse the repository at this point in the history
Fixes #140
  • Loading branch information
hadley committed Jan 26, 2021
1 parent 246c4ef commit 8354480
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# dtplyr (development version)

* `T` and `F` are correctly translated to `TRUE` and `FALSE` (#140).

# dtplyr 1.0.1

* Better handling for `.data` and `.env` pronouns (#138).
Expand Down
5 changes: 4 additions & 1 deletion R/tidyeval.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ dt_squash <- function(x, env, vars, j = TRUE) {
quote(.SD)
} else {
var <- as.character(x)
if (nchar(x) > 0 && substr(var, 1, 1) == ".") {

if (var %in% c("T", "F")) {
as.logical(var)
} else if (nchar(x) > 0 && substr(var, 1, 1) == ".") {
# data table pronouns are bound to NULL
x
} else if (j && !var %in% vars && env_has(env, var, inherit = TRUE)) {
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-tidyeval.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ test_that("simple expressions left as is", {
expect_equal(capture_dot(dt, 10), 10)
expect_equal(capture_dot(dt, x), quote(x))
expect_equal(capture_dot(dt, x + y), quote(x + y))

# logicals
expect_equal(eval(capture_dot(dt, T), globalenv()), TRUE)
expect_equal(eval(capture_dot(dt, F), globalenv()), FALSE)
expect_equal(capture_dot(dt, TRUE), TRUE)
expect_equal(capture_dot(dt, FALSE), FALSE)
})

test_that("existing non-variables get inlined", {
Expand Down

0 comments on commit 8354480

Please sign in to comment.