Skip to content

Commit

Permalink
apacheGH-43194: [R] R_existsVarInFrame isn't available earlier than R…
Browse files Browse the repository at this point in the history
… 4.2 (apache#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 apache#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: apache#43194

Authored-by: Jonathan Keane <jkeane@gmail.com>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
  • Loading branch information
jonkeane authored Jul 14, 2024
1 parent 7184150 commit 0372617
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions r/src/arrow_cpp11.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_));
Expand Down

0 comments on commit 0372617

Please sign in to comment.