This is an automated email from the ASF dual-hosted git repository.
jonkeane pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 0dec116d83 MINOR: [R] Work around test failure in tidyquery revdep
(#43498)
0dec116d83 is described below
commit 0dec116d83e4160aa3387fa87be2a99ac0fd3390
Author: Neal Richardson <[email protected]>
AuthorDate: Wed Jul 31 17:09:44 2024 -0400
MINOR: [R] Work around test failure in tidyquery revdep (#43498)
### Rationale for this change
See https://github.com/apache/arrow/issues/43317#issuecomment-2261299681.
`tidyquery` is assembling queries in some way such that when
`summarize.arrow_dplyr_query()` is called, the calling environment isn't a
call, so `match.call()` fails.
### What changes are included in this PR?
This PR wraps the `match.call()` call in a `try()`. The call is only used
to do `abandon_ship()` on in-memory data anyway. So if the call is not
available, it treats it like you're making a query on a Dataset and it tells
you to `collect()` yourself.
### Are these changes tested?
I couldn't figure out how to reproduce what was going on inside `tidyquery`
to write a reproducer, and I don't think this is worth adding `tidyquery` to
Suggests for. I confirmed locally that `tidyquery` tests pass with this change,
so our revdeps should be clear.
### Are there any user-facing changes?
🙅
Authored-by: Neal Richardson <[email protected]>
Signed-off-by: Jonathan Keane <[email protected]>
---
r/R/dplyr-eval.R | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/r/R/dplyr-eval.R b/r/R/dplyr-eval.R
index 1997d698c0..2dce24117a 100644
--- a/r/R/dplyr-eval.R
+++ b/r/R/dplyr-eval.R
@@ -201,7 +201,12 @@ try_arrow_dplyr <- function(expr) {
parent <- caller_env()
# Make sure that the call is available in the parent environment
# so that we can use it in abandon_ship, if needed
- evalq(call <- match.call(), parent)
+ # (but don't error if we're in some weird context where we can't get the
call,
+ # which could happen if you're code-generating or something?)
+ try(
+ evalq(call <- match.call(), parent),
+ silent = !getOption("arrow.debug", FALSE)
+ )
tryCatch(
eval(expr, parent),
@@ -217,7 +222,10 @@ try_arrow_dplyr <- function(expr) {
# and that the function being called also exists in the dplyr namespace.
abandon_ship <- function(err, env) {
.data <- get(".data", envir = env)
- if (query_on_dataset(.data)) {
+ # 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")) {
# Add a note suggesting `collect()` to the error message.
# If there are other suggestions already there (with the > arrow name),
# collect() isn't the only suggestion, so message differently
@@ -231,7 +239,6 @@ abandon_ship <- function(err, env) {
}
# Else, warn, collect(), and run in regular dplyr
- call <- get("call", envir = env)
rlang::warn(
message = paste0("In ", format_expr(err$call), ": "),
body = c("i" = conditionMessage(err), ">" = "Pulling data into R")