tidyverse / dtplyr

Data table backend for dplyr
https://dtplyr.tidyverse.org
Other
670 stars 57 forks source link

Inject syms that start with "." but aren't data.table syms #387

Closed eutwt closed 2 years ago

eutwt commented 2 years ago

closes #386

library(dplyr, w = FALSE)
library(dtplyr, w = FALSE)

f <- function(x, .v) {
  mutate(x, a = .v)
}

x <- data.frame(a = "y")

lazy_dt(x) |>
  f(.v = "injected")
#> Source: local data table [1 x 1]
#> Call:   copy(`_DT1`)[, `:=`(a = "injected")]
#> 
#>   a       
#>   <chr>   
#> 1 injected
#> 
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results

Created on 2022-08-15 by the reprex package (v2.0.1.9000)

eutwt commented 2 years ago

Another option would be to just delete lines 80-82. I think the only situation it affects is a user-supplied data.table pronoun symbol matching an environment variable. So if a user calls mutate(lazydt, y = .N) and they have .N <- 4 as an environment variable, they get a query like dt[, y := .N] instead of dt[, y := 4].

This seems pretty rare, and when it does happen we're creating behavior that diverges from dplyr. But, maybe people are relying on the existing behavior?

markfairbanks commented 2 years ago

I think you're right - deleting 80-82 would probably be fine. But I think the dt_symbols approach is the right one to use since it preserves backwards compatibility.