-
Notifications
You must be signed in to change notification settings - Fork 418
-
Notifications
You must be signed in to change notification settings - Fork 418
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
Should complete() and friends detect data masks in caller environment? #506
Comments
Related to |
Are you suggesting that How is this related to As for eval_tidy(tibble::lst(!!!ensyms(...)), .data) ? Do you see other advantages of having an explicit data mask in |
Behaving differently based on the caller is often the way to implement lexically scoped behaviour, i.e. the right thing to do. Passing the data mask is a way to pass the user's lexical context to
|
It doesn't work because:
In any case it'd be cleaner if tibble did forward the user context to |
Could you please inline the discussion from community, including a small reprex? |
Question was basically why Now there is a better error message thrown that tells you what to do so, FWIW, I don't think it's really problematic at this point. library(tidyverse)
d <- mtcars %>%
mutate_at(vars(carb, am), as.factor)
# desired behaviour works with this syntax
d %>%
group_by(carb, am) %>%
tally() %>%
complete(am, nesting(carb), fill = list(n = 0))
#> # A tibble: 12 x 3
#> # Groups: carb [6]
#> am carb n
#> <fct> <fct> <dbl>
#> 1 0 1 3
#> 2 1 1 4
#> 3 0 2 6
#> 4 1 2 4
#> 5 0 3 3
#> 6 1 3 0
# in a function, `nest` does not work with a quosure
fnc <- function(group, nest, data) {
group <- enquo(group)
nest <- enquo(nest)
data %>%
group_by(!!group, !!nest) %>%
tally() %>%
complete(!!group, nesting(!!nest), fill = list(n = 0))
}
fnc(am, carb, d)
#> Error in eval_tidy(xs[[i]], unique_output): object 'carb' not found
# uses `ensym()` for nest rather than `enquo()`
fnc2 <- function(group, nest, data) {
group <- enquo(group)
nest <- ensym(nest)
data %>%
group_by(!!nest, !!group) %>%
tally() %>%
complete(!!group, nesting(!!nest), fill = list(n = 0))
}
fnc2(am, carb, d)
#> # A tibble: 12 x 3
#> # Groups: carb [6]
#> am carb n
#> <fct> <fct> <dbl>
#> 1 0 1 3
#> 2 1 1 4
#> 3 0 2 6
#> 4 1 2 4
#> 5 0 3 3
#> 6 1 3 0 Created on 2019-01-04 by the reprex package (v0.2.1.9000) |
And should
lst()
take an optional mask as argument? cc @krlmlrhttps://community.rstudio.com/t/how-to-make-complete-nesting-work-with-quosures-and-tidyeval/16473/4
The text was updated successfully, but these errors were encountered: