[R] abandon_ship() looks up `call` with an inheriting get(), so its "no call" guard never fires

Aperta Adatta ai principianti
#55,793 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@dragonknightk ci sta già lavorando.

Dal 26/11/2026.

  • #55797 di @dragonknightk — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
r
Ambito
backend, data

Direzione di ricerca

Inizia da r/R/dplyr-eval.R, in particolare da abandon_ship() attorno alla ricerca della chiamata alle righe 252–255, e leggi i commenti e i test nelle vicinanze relativi alle espressioni dplyr non supportate. Riproduci il caso del wrapper dell’issue, poi controlla il comportamento con la ricerca proposta senza ereditarietà. Il lavoro è concluso quando il wrapper genera l’errore documentato arrow_not_supported mentre una chiamata diretta mantiene il fallback esistente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Component: R
Describe the bug, including details regarding any error messages, version, and platform.

When an arrow dplyr verb is reached through a function that forwards ..., and the expression cannot be translated, the user gets

Error in `call$.data <- dplyr::collect(.data)`:
! object of type 'special' is not subsettable

instead of either the documented fallback to R or the arrow_not_supported error that abandon_ship() is written to raise in this situation.

Reproducer
library(arrow, warn.conflicts = FALSE)
library(dplyr, warn.conflicts = FALSE)

tab <- arrow_table(k = c("a", "a", "b"), v = 1:3)

# Direct call: an expression Arrow cannot translate warns and falls back to R.
summarise(tab, out = dplyr::first(v))
#> Warning: In dplyr::first(v): 
#> ℹ Expression not supported in Arrow
#> → Pulling data into R
#> # A tibble: 1 × 1
#>     out
#>   <int>
#> 1     1

# The same call through a wrapper that forwards `...` errors instead.
wrapper <- function(.data, ...) dplyr::summarise(.data, ...)
wrapper(tab, out = dplyr::first(v))
#> Warning: In dplyr::first(v): 
#> ℹ Expression not supported in Arrow
#> → Pulling data into R
#> Error in `call$.data <- dplyr::collect(.data)`:
#> ! object of type 'special' is not subsettable

# The condition carries no Arrow class.
err <- tryCatch(
  suppressWarnings(wrapper(tab, out = dplyr::first(v))),
  error = identity
)
class(err)
#> [1] "notSubsettableError" "error"               "condition"

# What abandon_ship()'s lookup returns when `call` was never bound in `env`:
env <- new.env()
found <- try(get("call", envir = env), silent = TRUE)
identical(found, base::call)
#> [1] TRUE
inherits(found, "try-error")
#> [1] FALSE

# With `inherits = FALSE` the existing guard would fire:
found <- try(get("call", envir = env, inherits = FALSE), silent = TRUE)
inherits(found, "try-error")
#> [1] TRUE

Created on 2026-11-26 with reprex v2.1.1

summarise() is only the example. mutate(), filter() and arrange() fail the same way through an equivalent wrapper, as do grouped queries and RecordBatch input. Only in-memory input is affected: a Dataset through the same wrapper already gets arrow_not_supported, and an expression Arrow can translate works through the wrapper as usual.

Cause

try_arrow_dplyr() captures the verb's call for later use (r/R/dplyr-eval.R#L233-L236):

try(
  evalq(call <- match.call(), parent),
  silent = !getOption("arrow.debug", FALSE)
)

When the verb's own call contains ..., this match.call() fails with ... used in a situation where it does not exist, so call is never bound in parent. The error is silenced unless options(arrow.debug = TRUE) is set. It does not need arrow to reproduce:

# try_arrow_dplyr()'s capture, reduced to base R.
capture <- function() {
  parent <- parent.frame()
  try(evalq(call <- match.call(), parent))
  exists("call", envir = parent, inherits = FALSE)
}
verb <- function(.data, ...) capture()
wrapper <- function(.data, ...) verb(.data, ...)

verb(1, a = 1)
#> [1] TRUE
wrapper(1, a = 1)
#> Error in match.call() : ... used in a situation where it does not exist
#> [1] FALSE

Created on 2026-11-26 with reprex v2.1.1

abandon_ship() anticipates the missing binding (#L252-L255):

# 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)
if (query_on_dataset(.data) || inherits(call, "try-error")) {

but get() inherits by default, so the lookup walks out of env and returns base::call. That is not a try-error, the guard is skipped, and execution reaches call$.data <- dplyr::collect(.data), which tries to subset a special. Since R evaluates the right-hand side first, the whole input is collected before the error is raised.

Suggested fix
- call <- try(get("call", envir = env), silent = TRUE)
+ call <- try(get("call", envir = env, inherits = FALSE), silent = TRUE)

With only that line patched in a session, the wrapper gets the classed error and the direct call is unaffected:

library(arrow, warn.conflicts = FALSE)
library(dplyr, warn.conflicts = FALSE)

# Patch the one lookup in abandon_ship() for this session.
ns <- asNamespace("arrow")
fn <- get("abandon_ship", ns)
src <- deparse(body(fn))
src <- sub(
  'get("call", envir = env)',
  'get("call", envir = env, inherits = FALSE)',
  src,
  fixed = TRUE
)
body(fn) <- parse(text = src)[[1]]
assignInNamespace("abandon_ship", fn, ns)

tab <- arrow_table(k = c("a", "a", "b"), v = 1:3)
wrapper <- function(.data, ...) dplyr::summarise(.data, ...)

# Through the wrapper: the classed error the source comments describe.
wrapper(tab, out = dplyr::first(v))
#> Error in `dplyr::first()`:
#> ! Expression not supported in Arrow
#> → Call collect() first to pull data into R.
err <- tryCatch(wrapper(tab, out = dplyr::first(v)), error = identity)
class(err)
#> [1] "arrow_not_supported" "rlang_error"         "error"              
#> [4] "condition"

# Direct call: the fallback is unchanged.
summarise(tab, out = dplyr::first(v))
#> Warning: In dplyr::first(v): 
#> ℹ Expression not supported in Arrow
#> → Pulling data into R
#> # A tibble: 1 × 1
#>     out
#>   <int>
#> 1     1

Created on 2026-11-26 with reprex v2.1.1

This makes the guard do what it says. It does not make the fallback work through a wrapper: that would need the call captured some other way than match.call() under evalq(), which I have not attempted here.

History

The evalq(call <- match.call(), parent) capture and the inheriting get("call", envir = env) both date from #41576, which changed abandon_ship() to look the call up instead of receiving it as an argument. #43498 then wrapped the match.call() in try(), moved the get() into a try() of its own, and added the inherits(call, "try-error") test, to stop tidyquery's revdep failure seen in #43317. That PR notes that no reproducer could be written at the time; the wrapper above is one, and it shows the guard added there has not been firing.

I ran the code above on 26.0.1.1 only. From reading the source, the same lines are in every CRAN release from 17.0.0 (built from maint-17.0.0-r, which carries #43498) and on main. Up to 16.x, abandon_ship() received the call as an argument and this path did not exist.

Why it matters for calling code

Forwarding ... to a dplyr verb is the ordinary way to write a function or package on top of dplyr, so this is reachable without anything unusual. The resulting notSubsettableError cannot be told apart from any other misuse of $, whereas arrow_not_supported can be caught and names the offending expression.

Versions
  • arrow 26.0.1.1 (CRAN)
  • dplyr 1.2.1
  • R 4.6.2
  • macOS 27.2.1, aarch64

Drafted with an AI assistant (Claude). The three code blocks marked as reprex output are unedited output from the versions listed.

Component(s)

R

Lingua principale
C++
Stelle
17.3k
Fork
4.5k
Merge medio
3g 14h
PR unite (30g)
90

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/arrow

Tutte le issue di apache/arrow

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.