diff --git a/r/R/dplyr-eval.R b/r/R/dplyr-eval.R index 18fe1eb7c130..e40867b14a13 100644 --- a/r/R/dplyr-eval.R +++ b/r/R/dplyr-eval.R @@ -251,7 +251,7 @@ abandon_ship <- function(err, env) { .data <- get(".data", envir = env) # If there's no call (see comment in try_arrow_dplyr), we can't eval with # dplyr even if the data is in memory already - call <- try(get("call", envir = env), silent = TRUE) + call <- try(get("call", envir = env, inherits = FALSE), silent = TRUE) if (query_on_dataset(.data) || inherits(call, "try-error")) { # Add a note suggesting `collect()` to the error message. # If there are other suggestions already there (with the > arrow name), diff --git a/r/tests/testthat/test-dplyr-eval.R b/r/tests/testthat/test-dplyr-eval.R index 78bd84eb6d21..106946fca76f 100644 --- a/r/tests/testthat/test-dplyr-eval.R +++ b/r/tests/testthat/test-dplyr-eval.R @@ -60,6 +60,28 @@ test_that("try_arrow_dplyr/abandon_ship adds the right message about collect()", } }) +test_that("abandon_ship errors when the call can't be captured (GH-55793)", { + # Through a wrapper that forwards `...`, try_arrow_dplyr() can't capture the + # call, so abandon_ship() can't fall back to dplyr. It should raise + # arrow_not_supported, as it does for a Dataset. + tab <- arrow_table(x = 1:3) + summarise_wrapper <- function(.data, ...) dplyr::summarise(.data, ...) + mutate_wrapper <- function(.data, ...) dplyr::mutate(.data, ...) + + expect_error( + summarise_wrapper(tab, y = dplyr::first(x)), + "Call collect() first to pull data into R", + fixed = TRUE, + class = "arrow_not_supported" + ) + expect_error( + mutate_wrapper(tab, y = dplyr::first(x)), + "Call collect() first to pull data into R", + fixed = TRUE, + class = "arrow_not_supported" + ) +}) + test_that("dplyr verbs error clearly on empty column names", { skip_if_not_available("acero") # GH-40303