-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
... are further delayed in top_across() #5815
Conversation
1661c4c
to
ca4d651
Compare
ca4d651
to
d4fd1e0
Compare
92c3668
to
9f724b5
Compare
Avoid evaluating `top_across()` in a data mask because this promises the expressions in `...` within a different context than their evaluation. Since quosure evaluation trigger a data mask rechain, the data mask is not necessarily still chained to the caller environment when the dots are eventually evaluated.
9f724b5
to
ff6aaf3
Compare
ff6aaf3
to
67d524e
Compare
Ready for another round of review @romainfrancois |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @lionel-. This looks great.
Eventually we might have more than expand_across()
, i.e. other things to do with summarise(...=)
but in the meantime, this looks great.
#' # Inside `across()`: 6 normal variates (ncol * ngroup) | ||
#' gdf %>% mutate(across(v1:v2, ~ .x + rnorm(1))) | ||
#' ```` | ||
#' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that reads great.
@@ -339,26 +386,75 @@ key_deparse <- function(key) { | |||
# list(mean_x = expr(mean(x)), mean_y = expr(mean(y))) | |||
# columns = c("x", "y") | |||
# ) | |||
top_across <- function(.cols = everything(), .fns = NULL, ..., .names = NULL) { | |||
|
|||
expand_across <- function(quo) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that's a better name :-)
# Expand dots in lexical env | ||
env <- quo_get_env(quo) | ||
expr <- match.call( | ||
definition = across, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. I didn't realize you could definition=
@@ -256,7 +256,7 @@ mutate_cols <- function(.data, ..., caller_env) { | |||
|
|||
# get results from all the quosures that are expanded from ..i | |||
# then ingest them after | |||
quosures <- expand_quosure(dots[[i]]) | |||
quosures <- expand_across(dots[[i]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some point we might want to do more than "expand across" here, e.g. perhaps we can expand if_any/all()
also, and generally have some sort of mechanism for setup work, so we might add another layer, but for the moment this is more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup that makes sense.
closes #5813
Created on 2021-03-11 by the reprex package (v0.3.0)