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

Allow usage of default .cols in across() #231

Merged
merged 3 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
* `.data` and `.env` pronouns now work inside of `if_else()` (@markfairbanks, #220).

* `arrange(dt, desc(col))` is now translated to `dt[order(-col)]` in order to utilize
`data.table`'s fast order.
`data.table`'s fast order (@markfairbanks, #227).

* `across()` now defaults to `.cols = everything()` when `.cols` isn't provided (@markfairbanks, #231).

* More translations for tidyr verbs have been added:

Expand Down
3 changes: 2 additions & 1 deletion R/tidyeval-across.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ dt_squash_across <- function(call, env, data, j = j) {
call <- match.call(dplyr::across, call, expand.dots = FALSE, envir = env)

tbl <- simulate_vars(data, drop_groups = TRUE)
locs <- tidyselect::eval_select(call$.cols, tbl, allow_rename = FALSE)
.cols <- call$.cols %||% expr(everything())
locs <- tidyselect::eval_select(.cols, tbl, allow_rename = FALSE)
cols <- syms(names(tbl))[locs]

funs <- across_funs(call$.fns, env, data, j = j)
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-step-mutate.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ test_that("can use across", {
dt %>% mutate(across(everything(), ~ . + 1)) %>% show_query(),
expr(copy(DT)[, `:=`(x = x + 1, y = y + 1)])
)

expect_equal(
dt %>% mutate(across(.fns = ~ . + 1)) %>% show_query(),
expr(copy(DT)[, `:=`(x = x + 1, y = y + 1)])
)
})

test_that("vars set correctly", {
Expand Down