thisisnic commented on code in PR #13786:
URL: https://github.com/apache/arrow/pull/13786#discussion_r945778107
##########
r/tests/testthat/test-dplyr-mutate.R:
##########
@@ -589,3 +588,127 @@ test_that("mutate() and transmute() with namespaced
functions", {
tbl
)
})
+
+test_that("Can use across() within mutate()", {
+ compare_dplyr_binding(
+ .input %>%
+ mutate(across(c(dbl, dbl2), round)) %>%
+ collect(),
+ tbl
+ )
+
+ compare_dplyr_binding(
+ .input %>%
+ mutate(across(c(dbl, dbl2), list(exp, sqrt))) %>%
+ collect(),
+ tbl
+ )
+
+ compare_dplyr_binding(
+ .input %>%
+ mutate(across(c(dbl, dbl2), list("fun1" = round, "fun2" = sqrt))) %>%
+ collect(),
+ tbl
+ )
+
+ # this is valid is neither R nor Arrow
+ expect_error(
+ expect_warning(
+ compare_dplyr_binding(
+ .input %>%
+ arrow_table() %>%
+ mutate(across(c(dbl, dbl2), list("fun1" = round(sqrt(dbl))))) %>%
+ collect(),
+ tbl,
+ warning = TRUE
+ )
+ )
+ )
+
+ # across() arguments not in default order
+ compare_dplyr_binding(
+ .input %>%
+ mutate(across(.fns = round, c(dbl, dbl2))) %>%
+ collect(),
+ tbl
+ )
+
+ # ARROW-17364: .names argument not yet supported for across()
+ expect_error(
+ tbl %>%
+ arrow_table() %>%
+ mutate(across(c(dbl, dbl2), round, .names = "{.col}.{.fn}")) %>%
+ collect(),
+ regexp = "`.names` argument to `across()` not yet supported in Arrow",
+ fixed = TRUE
+ )
+
+ # ellipses (...) are a deprecated argument
+ expect_error(
+ tbl %>%
+ arrow_table() %>%
+ mutate(across(c(dbl, dbl2), round, digits = -1)) %>%
+ collect(),
+ regexp = "`...` argument to `across()` is deprecated in dplyr and not
supported in Arrow",
+ fixed = TRUE
+ )
+
+ # alternative ways of specifying .fns - as a list
+ compare_dplyr_binding(
+ .input %>%
+ mutate(across(1:dbl2, list(round))) %>%
+ collect(),
+ tbl
+ )
+
+ # supply .fns as a one-item vector
+ compare_dplyr_binding(
+ .input %>%
+ mutate(across(1:dbl2, c(round))) %>%
+ collect(),
+ tbl
+ )
+
+ # ARROW-17366: purrr-style lambda functions not yet supported
+ expect_error(
+ compare_dplyr_binding(
+ .input %>%
+ mutate(across(1:dbl2, ~ round(.x, digits = -1))) %>%
+ collect(),
+ tbl
+ ),
+ regexp = "purrr-style lambda functions as `.fns` argument to `across()`
not yet supported in Arrow",
+ fixed = TRUE
+ )
+
+ # .fns = NULL, the default
+ compare_dplyr_binding(
+ .input %>%
+ mutate(across(1:dbl2, NULL)) %>%
+ collect(),
+ tbl
+ )
+
+ expect_error(
+ compare_dplyr_binding(
+ .input %>%
+ mutate(across(where(is.double))) %>%
+ collect(),
+ tbl
+ ),
+ "Unsupported selection helper"
Review Comment:
`where()` isn't yet supported - have added a comment which links to the JIRA
for it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]