Skip to content
Draft
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
22 changes: 22 additions & 0 deletions r/R/dplyr-funcs-conditional.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,28 @@ register_bindings_conditional <- function() {
out
})

register_binding("dplyr::when_any", function(..., na_rm = FALSE, size = NULL) {
if (!is.null(size)) {
arrow_not_supported("`when_any()` with `size` specified")
}
args <- list2(...)
if (na_rm) {
args <- lapply(args, function(x) call_binding("coalesce", x, FALSE))
}
Reduce("|", args)
})

register_binding("dplyr::when_all", function(..., na_rm = FALSE, size = NULL) {
if (!is.null(size)) {
arrow_not_supported("`when_all()` with `size` specified")
}
args <- list2(...)
if (na_rm) {
args <- lapply(args, function(x) call_binding("coalesce", x, TRUE))
}
Reduce("&", args)
})

register_binding(
"dplyr::case_when",
function(..., .default = NULL, .ptype = NULL, .size = NULL) {
Expand Down
4 changes: 3 additions & 1 deletion r/R/dplyr-funcs-doc.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#'
#' The `arrow` package contains methods for 38 `dplyr` table functions, many of
#' which are "verbs" that do transformations to one or more tables.
#' The package also has mappings of 224 R functions to the corresponding
#' The package also has mappings of 226 R functions to the corresponding
#' functions in the Arrow compute library. These allow you to write code inside
#' of `dplyr` methods that call R functions, including many in packages like
#' `stringr` and `lubridate`, and they will get translated to Arrow and run
Expand Down Expand Up @@ -214,6 +214,8 @@
#' * [`if_else()`][dplyr::if_else()]
#' * [`n()`][dplyr::n()]
#' * [`n_distinct()`][dplyr::n_distinct()]
#' * [`when_all()`][dplyr::when_all()]
#' * [`when_any()`][dplyr::when_any()]
#'
#' ## hms
#'
Expand Down
4 changes: 3 additions & 1 deletion r/man/acero.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion r/man/read_json_arrow.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion r/man/schema.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions r/tests/testthat/test-dplyr-funcs-conditional.R
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,69 @@ test_that("external objects are found when they're not in the global environment
tibble(x = c("a", "b"), x2 = c("foo", NA))
)
})

test_that("when_any()", {
# combines with OR
compare_dplyr_binding(
.input |>
mutate(result = when_any(lgl, false)) |>
collect(),
tbl
)

# na_rm=TRUE treats NA as FALSE
compare_dplyr_binding(
.input |>
mutate(result = when_any(lgl, false, na_rm = TRUE)) |>
collect(),
tbl
)

# works in filter()
compare_dplyr_binding(
.input |>
filter(when_any(int > 5, dbl > 3)) |>
collect(),
tbl
)

# size not supported
expect_arrow_eval_error(
when_any(lgl, false, size = 10),
"`when_any\\(\\)` with `size` specified not supported in Arrow",
class = "arrow_not_supported"
)
})

test_that("when_all()", {
# combines with AND
compare_dplyr_binding(
.input |>
mutate(result = when_all(lgl, false)) |>
collect(),
tbl
)

# na_rm=TRUE treats NA as TRUE
compare_dplyr_binding(
.input |>
mutate(result = when_all(lgl, false, na_rm = TRUE)) |>
collect(),
tbl
)

# works in filter()
compare_dplyr_binding(
.input |>
filter(when_all(int > 5, dbl > 3)) |>
collect(),
tbl
)

# size not supported
expect_arrow_eval_error(
when_all(lgl, false, size = 10),
"`when_all\\(\\)` with `size` specified not supported in Arrow",
class = "arrow_not_supported"
)
})
Loading