@@ -208,14 +208,20 @@ Pointer r6_to_pointer(SEXP self) {
208208 cpp11::stop (" Invalid R object for %s, must be an ArrowObject" , type_name.c_str ());
209209 }
210210
211- #if R_VERSION >= R_Version(4, 5, 0)
212- SEXP xp = R_getVarEx (arrow::r::symbols::xp, self, FALSE , R_UnboundValue);
211+ #if R_VERSION >= R_Version(4, 6, 0)
212+ if (!R_existsVarInFrame (self, arrow::r::symbols::xp)) {
213+ cpp11::stop (" Invalid: self$`.:xp:.` is NULL" );
214+ }
215+ SEXP xp = R_getVar (arrow::r::symbols::xp, self, FALSE );
216+ if (xp == R_NilValue) {
217+ cpp11::stop (" Invalid: self$`.:xp:.` is NULL" );
218+ }
213219#else
214220 SEXP xp = Rf_findVarInFrame (self, arrow::r::symbols::xp);
215- #endif
216221 if (xp == R_UnboundValue || xp == R_NilValue) {
217222 cpp11::stop (" Invalid: self$`.:xp:.` is NULL" );
218223 }
224+ #endif
219225
220226 void * p = R_ExternalPtrAddr (xp);
221227 if (p == nullptr ) {
@@ -227,10 +233,16 @@ Pointer r6_to_pointer(SEXP self) {
227233
228234template <typename T>
229235void r6_reset_pointer (SEXP r6) {
230- #if R_VERSION >= R_Version(4, 5, 0)
231- SEXP xp = R_getVarEx (arrow::r::symbols::xp, r6, FALSE , R_UnboundValue);
236+ #if R_VERSION >= R_Version(4, 6, 0)
237+ if (!R_existsVarInFrame (r6, arrow::r::symbols::xp)) {
238+ return ;
239+ }
240+ SEXP xp = R_getVar (arrow::r::symbols::xp, r6, FALSE );
232241#else
233242 SEXP xp = Rf_findVarInFrame (r6, arrow::r::symbols::xp);
243+ if (xp == R_UnboundValue) {
244+ return ;
245+ }
234246#endif
235247 void * p = R_ExternalPtrAddr (xp);
236248 if (p != nullptr ) {
@@ -388,13 +400,12 @@ SEXP to_r6(const std::shared_ptr<T>& ptr, const char* r6_class_name) {
388400 cpp11::external_pointer<std::shared_ptr<T>> xp (new std::shared_ptr<T>(ptr));
389401 SEXP r6_class = Rf_install (r6_class_name);
390402
391- // R_existsVarInFrame doesn't exist before R 4.2, so we need to fall back to
392- // Rf_findVarInFrame3 if it is not defined.
393- #if R_VERSION >= R_Version(4, 2, 0)
403+ #if R_VERSION >= R_Version(4, 6, 0)
394404 if (!R_existsVarInFrame (arrow::r::ns::arrow, r6_class)) {
395405 cpp11::stop (" No arrow R6 class named '%s'" , r6_class_name);
396406 }
397407#else
408+ // Rf_findVarInFrame3 and R_UnboundValue are non-API as of R 4.6
398409 if (Rf_findVarInFrame3 (arrow::r::ns::arrow, r6_class, FALSE ) == R_UnboundValue) {
399410 cpp11::stop (" No arrow R6 class named '%s'" , r6_class_name);
400411 }
0 commit comments