From 5bee2d25031afcea37b18ae7d4b3e30c01af92cc Mon Sep 17 00:00:00 2001 From: dragonknightk <37928252+dragonknightk@users.noreply.github.com> Date: Thu, 26 Nov 2026 18:42:32 +0800 Subject: [PATCH] [R] Look up the captured call without inheritance in abandon_ship() ### Rationale for this change When a dplyr verb on a Table or RecordBatch is called through a wrapper that forwards `...`, and the expression can't be translated, the user gets "object of type 'special' is not subsettable" instead of the fallback to R or an `arrow_not_supported` error. In that case `match.call()` in `try_arrow_dplyr()` fails, so `call` is never bound. `abandon_ship()` has a guard for this, but its `get("call", envir = env)` inherits by default and finds `base::call`, so the guard never fires. ### What changes are included in this PR? Pass `inherits = FALSE` to that `get()`, so the guard fires when `call` was never bound. The fallback through a wrapper that forwards `...` still does not work, because the call can't be captured there. ### Are these changes tested? Yes. A Table passed through wrappers that forward `...` around `summarise()` and `mutate()`, with an untranslatable expression, now raises `arrow_not_supported` and includes the "Call collect() first to pull data into R" hint. Without the fix both raise "object of type 'special' is not subsettable". ### Are there any user-facing changes? Yes. Through a wrapper that forwards `...`, a Table or RecordBatch now raises `arrow_not_supported` with the hint to call `collect()`, the same as a Dataset already does. It no longer raises "object of type 'special' is not subsettable", and it no longer pulls the data into R first. Closes issue 55793 * GitHub Issue: (filled in automatically from the PR title) Signed-off-by: dragonknightk <37928252+dragonknightk@users.noreply.github.com> --- r/R/dplyr-eval.R | 2 +- r/tests/testthat/test-dplyr-eval.R | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) 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