From 03726178494c8978bf48b9bab15ed9676e7c9196 Mon Sep 17 00:00:00 2001 From: Jonathan Keane Date: Sun, 14 Jul 2024 08:46:33 -0500 Subject: [PATCH] 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 Signed-off-by: Jonathan Keane --- 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 5e6a7d5a42fb2..b2ed66b83c3d1 100644 --- a/r/src/arrow_cpp11.h +++ b/r/src/arrow_cpp11.h @@ -378,9 +378,17 @@ SEXP to_r6(const std::shared_ptr& ptr, const char* r6_class_name) { cpp11::external_pointer> xp(new std::shared_ptr(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: $new() SEXP call = PROTECT(Rf_lang3(R_DollarSymbol, r6_class, arrow::r::symbols::new_));