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

Ouverte Adaptée aux débutants
#55,793 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@dragonknightk y travaille déjà.

Depuis le 26/11/2026.

  • #55797 par @dragonknightk — ouverte

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
78/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
r
Domaine
backend, data

Piste de recherche

Commencez par r/R/dplyr-eval.R, en particulier abandon_ship() autour de la recherche d’appel aux lignes 252–255, et lisez les commentaires et les tests à proximité concernant les expressions dplyr non prises en charge. Reproduisez le cas du wrapper de l’issue, puis vérifiez le comportement avec la recherche proposée sans héritage. Le travail est terminé lorsque le wrapper déclenche l’erreur documentée arrow_not_supported tandis qu’un appel direct conserve son fallback actuel.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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

Langage dominant
C++
Étoiles
17.3k
Forks
4.5k
Merge moyen
3 j 14 h
PR mergées (30 j)
90

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de apache/arrow

Toutes les issues de apache/arrow

Issues similaires

Plus d'issues C++

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.