This is an automated email from the ASF dual-hosted git repository.

jonkeane pushed a commit to branch maint-17.0.0-r
in repository https://gitbox.apache.org/repos/asf/arrow.git

commit 5dabe5da316f280902318109b34d2ffab41b52ab
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_));

Reply via email to