Skip to content

Commit 7aca682

Browse files
authored
GH-49649: [R] R non-API calls reported on CRAN (#49653)
### Rationale for this change CRAN reports non-API calls ### What changes are included in this PR? Swap 'em out ### Are these changes tested? I'll test with CI ### Are there any user-facing changes? Nah ### AI usage Used Claude, asked it lots of questions about what it was doing and why, answers sounded reasonable. * GitHub Issue: #49649 Authored-by: Nic Crane <thisisnic@gmail.com> Signed-off-by: Nic Crane <thisisnic@gmail.com>
1 parent 6cefbd3 commit 7aca682

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

r/src/arrow_cpp11.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,26 @@ 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)
211+
// R_UnboundValue and Rf_findVarInFrame are non-API as of R 4.6
212+
#if R_VERSION >= R_Version(4, 6, 0)
213+
SEXP xp = R_NilValue;
214+
if (R_existsVarInFrame(self, arrow::r::symbols::xp)) {
215+
xp = R_getVar(arrow::r::symbols::xp, self, FALSE);
216+
}
217+
if (xp == R_NilValue) {
218+
cpp11::stop("Invalid: self$`.:xp:.` is NULL");
219+
}
220+
#elif R_VERSION >= R_Version(4, 5, 0)
212221
SEXP xp = R_getVarEx(arrow::r::symbols::xp, self, FALSE, R_UnboundValue);
222+
if (xp == R_UnboundValue || xp == R_NilValue) {
223+
cpp11::stop("Invalid: self$`.:xp:.` is NULL");
224+
}
213225
#else
214226
SEXP xp = Rf_findVarInFrame(self, arrow::r::symbols::xp);
215-
#endif
216227
if (xp == R_UnboundValue || xp == R_NilValue) {
217228
cpp11::stop("Invalid: self$`.:xp:.` is NULL");
218229
}
230+
#endif
219231

220232
void* p = R_ExternalPtrAddr(xp);
221233
if (p == nullptr) {
@@ -227,7 +239,13 @@ Pointer r6_to_pointer(SEXP self) {
227239

228240
template <typename T>
229241
void r6_reset_pointer(SEXP r6) {
230-
#if R_VERSION >= R_Version(4, 5, 0)
242+
// R_UnboundValue and Rf_findVarInFrame are non-API as of R 4.6
243+
#if R_VERSION >= R_Version(4, 6, 0)
244+
if (!R_existsVarInFrame(r6, arrow::r::symbols::xp)) {
245+
return;
246+
}
247+
SEXP xp = R_getVar(arrow::r::symbols::xp, r6, FALSE);
248+
#elif R_VERSION >= R_Version(4, 5, 0)
231249
SEXP xp = R_getVarEx(arrow::r::symbols::xp, r6, FALSE, R_UnboundValue);
232250
#else
233251
SEXP xp = Rf_findVarInFrame(r6, arrow::r::symbols::xp);

0 commit comments

Comments
 (0)