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 0372617849 GH-43194: [R] R_existsVarInFrame isn't available earlier
than R 4.2 (#43243)
0372617849 is described below
commit 03726178494c8978bf48b9bab15ed9676e7c9196
Author: Jonathan Keane <[email protected]>
AuthorDate: Sun Jul 14 08:46:33 2024 -0500
GH-43194: [R] R_existsVarInFrame isn't available earlier than R 4.2 (#43243)
### Rationale for this change
`R_existsVarInFrame` doesn't exist before R 4.2, so we need to fall back to
`Rf_findVarInFrame3` if it is not defined.
Resolves #43194
### What changes are included in this PR?
`ifdef`s
### Are these changes tested?
Yes, in our extended CI `test-r-versions`,
`test-r-rstudio-r-base-4.1-opensuse155`
### Are there any user-facing changes?
No
* GitHub Issue: #43194
Authored-by: Jonathan Keane <[email protected]>
Signed-off-by: Jonathan Keane <[email protected]>
---
r/src/arrow_cpp11.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/r/src/arrow_cpp11.h b/r/src/arrow_cpp11.h
index 5e6a7d5a42..b2ed66b83c 100644
--- a/r/src/arrow_cpp11.h
+++ b/r/src/arrow_cpp11.h
@@ -378,9 +378,17 @@ SEXP to_r6(const std::shared_ptr<T>& ptr, const char*
r6_class_name) {
cpp11::external_pointer<std::shared_ptr<T>> xp(new std::shared_ptr<T>(ptr));
SEXP r6_class = Rf_install(r6_class_name);
+// R_existsVarInFrame doesn't exist before R 4.2, so we need to fall back to
+// Rf_findVarInFrame3 if it is not defined.
+#ifdef R_existsVarInFrame
if (!R_existsVarInFrame(arrow::r::ns::arrow, r6_class)) {
cpp11::stop("No arrow R6 class named '%s'", r6_class_name);
}
+#else
+ if (Rf_findVarInFrame3(arrow::r::ns::arrow, r6_class, FALSE) ==
R_UnboundValue) {
+ cpp11::stop("No arrow R6 class named '%s'", r6_class_name);
+ }
+#endif
// make call: <symbol>$new(<x>)
SEXP call = PROTECT(Rf_lang3(R_DollarSymbol, r6_class,
arrow::r::symbols::new_));