Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 16, 2022

Conversation

eutwt
Copy link
Collaborator

@eutwt eutwt commented Aug 16, 2022

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
Copy link
Collaborator Author

eutwt commented Aug 16, 2022

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
Copy link
Collaborator

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.

@eutwt eutwt requested a review from markfairbanks August 16, 2022 14:40
@eutwt eutwt merged commit bf300c4 into main Aug 16, 2022
@eutwt eutwt deleted the better-dtsym-check branch August 16, 2022 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Function calls in functions can not access to environment variables in parent functions
2 participants