Skip to content

Commit

Permalink
GH-43194: [R] R_existsVarInFrame isn't available earlier than R 4.2 (#…
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
jonkeane committed Jul 18, 2024
1 parent 708d177 commit 5dabe5d
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 5dabe5d

Please sign in to comment.