Skip to content

Commit

Permalink
Merge pull request #325 from tidyverse/if_any-default-fns-arg
Browse files Browse the repository at this point in the history
`if_any/all()` work without specifying `.fns`
  • Loading branch information
markfairbanks authored Feb 6, 2022
2 parents 405032e + dcb2630 commit 0f0738d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# dtplyr (development version)

* `if_any()` and `if_all()` now work without specifying the `.fns` argument (@mgirlich, #325).

# dtplyr 1.2.1

* Fix for upcoming rlang release.
Expand Down
4 changes: 4 additions & 0 deletions R/tidyeval-across.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ dt_squash_if <- function(call, env, data, j = j, reduce = "&") {
locs <- tidyselect::eval_select(.cols, tbl, allow_rename = FALSE)
cols <- syms(names(tbl))[locs]

if (is.null(call$.fns)) {
return(Reduce(function(x, y) call2(reduce, x, y), cols))
}

fun <- across_fun(call$.fns, env, data, j = j)

out <- vector("list", length(cols))
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-tidyeval-across.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,8 @@ test_that("if_all collapses multiple expresions", {
dt <- lazy_dt(data.frame(a = 1, b = 2))
expect_equal(capture_if_all(dt, if_all(everything(), is.na)), expr(is.na(a) & is.na(b)))
})

test_that("if_all works without `.fns` argument", {
dt <- lazy_dt(data.frame(a = 1, b = 2))
expect_equal(capture_if_all(dt, if_all(c(a:b))), expr(a & b))
})

0 comments on commit 0f0738d

Please sign in to comment.