From 6649d60adf76bed0947314a7b13f76b3e9100f11 Mon Sep 17 00:00:00 2001 From: Maximilian Girlich Date: Thu, 16 Dec 2021 07:08:31 +0000 Subject: [PATCH] `if_any/all()` work without specifying `.fns` --- NEWS.md | 2 ++ R/tidyeval-across.R | 4 ++++ tests/testthat/test-tidyeval-across.R | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/NEWS.md b/NEWS.md index d8d9e0b3f..beecd6637 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # dtplyr (development version) +* `if_any()` and `if_all()` now work without specifying the `.fns` argument (@mgirlich, #325). + # dtplyr 1.2.0 ## New authors diff --git a/R/tidyeval-across.R b/R/tidyeval-across.R index 860fd5d2f..8c3994c13 100644 --- a/R/tidyeval-across.R +++ b/R/tidyeval-across.R @@ -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)) diff --git a/tests/testthat/test-tidyeval-across.R b/tests/testthat/test-tidyeval-across.R index 8b9f4b3d9..a219e7bb1 100644 --- a/tests/testthat/test-tidyeval-across.R +++ b/tests/testthat/test-tidyeval-across.R @@ -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)) +})