@@ -210,10 +210,10 @@ Pointer r6_to_pointer(SEXP self) {
210210
211211// R_UnboundValue and Rf_findVarInFrame are non-API as of R 4.6
212212#if R_VERSION >= R_Version(4, 6, 0)
213- if (!R_existsVarInFrame (self, arrow::r::symbols::xp)) {
214- cpp11::stop (" Invalid: self$`.:xp:.` is NULL" );
213+ SEXP xp = R_NilValue;
214+ if (R_existsVarInFrame (self, arrow::r::symbols::xp)) {
215+ xp = R_getVar (arrow::r::symbols::xp, self, FALSE );
215216 }
216- SEXP xp = R_getVar (arrow::r::symbols::xp, self, FALSE );
217217 if (xp == R_NilValue) {
218218 cpp11::stop (" Invalid: self$`.:xp:.` is NULL" );
219219 }
@@ -412,8 +412,8 @@ SEXP to_r6(const std::shared_ptr<T>& ptr, const char* r6_class_name) {
412412 cpp11::external_pointer<std::shared_ptr<T>> xp (new std::shared_ptr<T>(ptr));
413413 SEXP r6_class = Rf_install (r6_class_name);
414414
415- // Rf_findVarInFrame3 and R_UnboundValue are non-API as of R 4.6.
416- // R_existsVarInFrame doesn't exist before R 4.2 .
415+ // R_existsVarInFrame doesn't exist before R 4.2, so we need to fall back to
416+ // Rf_findVarInFrame3 if it is not defined .
417417#if R_VERSION >= R_Version(4, 2, 0)
418418 if (!R_existsVarInFrame (arrow::r::ns::arrow, r6_class)) {
419419 cpp11::stop (" No arrow R6 class named '%s'" , r6_class_name);
0 commit comments