-
Notifications
You must be signed in to change notification settings - Fork 58
across()
improvements
#335
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
Conversation
* Refactor out common parts for `dt_squash_across()` and `dt_squash_if()`. This fixes two things for `if_all()`: i) evaluate dots in correct env and ii) can use multiple functions * Formulas can now use `.y`
I like the simplification part of this PR - but before I do a code review I wanted to discuss the use of Basically I think we should error when In #287 @eutwt mentioned being able to do this: library(dplyr, warn.conflicts = FALSE)
df <- tibble(x = 1:3, y = 1:3)
df %>%
mutate(
across(c(x, y), ~ .x + .y, 1)
)
#> # A tibble: 3 × 2
#> x y
#> <dbl> <dbl>
#> 1 2 2
#> 2 3 3
#> 3 4 4 However library(dplyr, warn.conflicts = FALSE)
df <- tibble(x = 1:3, y = 1:3)
df %>%
mutate(
across(c(x, y), ~ .x + ..2 + ..3 + ..4, 1, 2, 3)
)
#> # A tibble: 3 × 2
#> x y
#> <dbl> <dbl>
#> 1 7 7
#> 2 8 8
#> 3 9 9 @mgirlich maybe you have a good idea to deal with situations like this with an arbitrary number of dots? But instead of supporting In the Open to thoughts though. |
Although I find the ability to use |
Fine for me to remove to support for dots, especially for purrr style lambdas. |
I think we should definitely error in the case where dots are used with a purrr-style lambda. It doesn't currently work anyway so it won't break backwards compatibility. However deprecating dots usage in general should be done with a deprecation lifecycle (if at all) since it currently works in dtplyr and also works in dplyr. I think a case like this should still work (without warnings) until dplyr makes the deprecation first. df <- data.table(x = 1:3, y = 1:3)
df %>%
summarize(
across(c(x, y), mean, na.rm = TRUE)
) |
R/tidyeval-across.R
Outdated
} else if (is_call(funs, "list")) { | ||
args <- rlang::exprs_auto_name(funs[-1]) | ||
lapply(args, across_fun, env, data, j = j) | ||
args <- rlang::call_args(funs) |
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.
Can drop rlang::
here
R/tidyeval-across.R
Outdated
"`dtplyr` does not support `...` in `across()` and `if_all()`.", | ||
i = "Use a lambda instead.", | ||
i = "Or inline them via purrr-style lambdas." |
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.
Should this say something like "`dtplyr` does not support `...` in `across()` and `if_all()` when a lambda is used in `.fns`."
?
Fixes the third point in #287.dt_squash_if()
anddt_squash_across()
to useacross_setup()
, very similar todplyr::across_setup()
.dplyr
. When passing a list to.fns
missing names are not guessed from the function but filled with a number.dplyr
).if_all()
.if_all()
.inject()
instead of deprecatedexpr_interp()