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 if_any() and if_all() #294

Merged
merged 4 commits into from
Sep 1, 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
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# dtplyr (development version)

* `if_any()` and `if_all()` now default to `.cols = everything()` when `.cols`
isn't provided (@eutwt, #294).

* `summarise()` now supports the `.groups` argument (@mgirlich, #245).

* `filter()` now errors for named input, e.g. `filter(dt, x = 1)` (@mgirlich, #267).
Expand Down
3 changes: 2 additions & 1 deletion R/tidyeval-across.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ dt_squash_if <- function(call, env, data, j = j, reduce = "&") {
call <- match.call(dplyr::if_any, 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]

fun <- across_fun(call$.fns, env, data, j = j)
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-step-subset-filter.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ test_that("can use with across", {
expr(DT[x > 0 | y > 0])
)

# .cols defaults to everything()
expect_equal(
dt %>% filter(if_all(.fns = ~ . > 0)) %>% show_query(),
expr(DT[x > 0 & y > 0 & z > 0])
)
expect_equal(
dt %>% filter(if_any(.fns = ~ . > 0)) %>% show_query(),
expr(DT[x > 0 | y > 0 | z > 0])
)
})

test_that("can filter when grouped", {
Expand Down