diff --git a/R/tidyeval.R b/R/tidyeval.R index d4d03f30..d7a4ba1c 100644 --- a/R/tidyeval.R +++ b/R/tidyeval.R @@ -18,6 +18,7 @@ dt_funs <- c( "fcase", "fcoalesce", "fifelse", "fintersect", "frank", "frankv", "fsetdiff", "funion", "setcolorder", "setnames", "setorder", "shift", "tstrsplit", "uniqueN" ) +dt_symbols <- c(".SD", ".BY", ".N", ".I", ".GRP", ".NGRP") add_dt_wrappers <- function(env) { env_bind(env, !!!env_get_list(ns_env("data.table"), dt_funs)) } @@ -77,7 +78,7 @@ dt_squash <- function(x, env, data, j = TRUE) { if (var %in% c("T", "F")) { as.logical(var) - } else if (nchar(x) > 0 && substr(var, 1, 1) == ".") { + } else if (var %in% dt_symbols) { # data table pronouns are bound to NULL x } else if (!var %in% data$vars && env_has(env, var, inherit = TRUE)) { diff --git a/tests/testthat/test-tidyeval.R b/tests/testthat/test-tidyeval.R index b59b8561..52ffb762 100644 --- a/tests/testthat/test-tidyeval.R +++ b/tests/testthat/test-tidyeval.R @@ -20,6 +20,9 @@ test_that("existing non-variables get inlined", { n <- 10 expect_equal(capture_dot(dt, x + n), quote(x + 10)) expect_equal(capture_dot(dt, x + m), quote(x + m)) + # even if they start with "." (#386) + .n <- 20 + expect_equal(capture_dot(dt, x + .n), quote(x + 20)) }) test_that("unless we're operating in the global environment", {