diff --git a/NEWS.md b/NEWS.md index 595fbda22..69f59f464 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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). diff --git a/R/tidyeval.R b/R/tidyeval.R index bcbd69413..918765f0a 100644 --- a/R/tidyeval.R +++ b/R/tidyeval.R @@ -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)) { diff --git a/tests/testthat/test-tidyeval.R b/tests/testthat/test-tidyeval.R index 82cf95781..b564a94a9 100644 --- a/tests/testthat/test-tidyeval.R +++ b/tests/testthat/test-tidyeval.R @@ -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", {