This is an automated email from the ASF dual-hosted git repository.

paleolimbot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-nanoarrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 4bbcf0e3 Use R_hasAttrib (from R 4.6.0 or later) to avoid ATTRIB (#842)
4bbcf0e3 is described below

commit 4bbcf0e347078ce391d0a576b25fd2f69431ea84
Author: Dirk Eddelbuettel <[email protected]>
AuthorDate: Fri Jan 30 20:02:52 2026 -0600

    Use R_hasAttrib (from R 4.6.0 or later) to avoid ATTRIB (#842)
    
    It looks like CRAN is unhappy about a remaining use of `ATTRIB`. Having
    dealt with that myself, I think that `R_hasAttrib()`, added in R 4.6.0,
    should be a fine replacement for you. I am not 100% sure it is
    ALTREP-safe --- it says neither yay nor nay --- but I think it is as it
    does pretty much what you do here:
    
    ```
    bool R_hasAttrib(SEXP x, SEXP name)
    {
        if (isScalarString(name)) name = installTrChar(STRING_ELT(name, 0));
        if (! isSymbol(name))
            error(_("'name' is not a symbol or a scalar string"));
        if (name == R_NamesSymbol && isListWithNames(x))
            return true;
        SEXP attr = ATTRIB(x);
        while (attr != R_NilValue) {
            if (TAG(attr) == name)
                return true;
            attr = CDR(attr);
        }
        return false;
    }
    ```
    
    (The PR also adds an `importFrom` as R(-devel) CMD check complained.)
---
 r/NAMESPACE          | 1 +
 r/R/pkg-reticulate.R | 1 +
 r/src/materialize.c  | 5 +++++
 3 files changed, 7 insertions(+)

diff --git a/r/NAMESPACE b/r/NAMESPACE
index 313d3b32..a4b4df14 100644
--- a/r/NAMESPACE
+++ b/r/NAMESPACE
@@ -226,5 +226,6 @@ export(test_reticulate_with_nanoarrow)
 export(unregister_nanoarrow_extension)
 export(write_nanoarrow)
 importFrom(utils,getFromNamespace)
+importFrom(utils,packageVersion)
 importFrom(utils,str)
 useDynLib(nanoarrow, .registration = TRUE)
diff --git a/r/R/pkg-reticulate.R b/r/R/pkg-reticulate.R
index 5ca7608e..39e66a8d 100644
--- a/r/R/pkg-reticulate.R
+++ b/r/R/pkg-reticulate.R
@@ -161,6 +161,7 @@ py_to_r.nanoarrow.array_stream.ArrayStream <- function(x) {
 }
 
 #' @rdname as_nanoarrow_schema.python.builtin.object
+#' @importFrom utils packageVersion
 #' @export
 test_reticulate_with_nanoarrow <- function() {
   identical(Sys.getenv("NANOARROW_R_TEST_RETICULATE"), "true") &&
diff --git a/r/src/materialize.c b/r/src/materialize.c
index 2d42245e..ca4d7614 100644
--- a/r/src/materialize.c
+++ b/r/src/materialize.c
@@ -18,6 +18,7 @@
 #define R_NO_REMAP
 #include <R.h>
 #include <Rinternals.h>
+#include <Rversion.h>
 
 #include "array.h"
 #include "nanoarrow.h"
@@ -57,10 +58,14 @@ SEXP nanoarrow_alloc_type(enum VectorType vector_type, 
R_xlen_t len) {
 // A version of Rf_getAttrib(x, sym) != R_NilValue that never
 // expands the row.names attribute
 static int has_attrib_safe(SEXP x, SEXP sym) {
+#if R_VERSION >= R_Version(4, 6, 0)
+  return (int)R_hasAttrib(x, sym);
+#else
   for (SEXP atts = ATTRIB(x); atts != R_NilValue; atts = CDR(atts)) {
     if (TAG(atts) == sym) return TRUE;
   }
   return FALSE;
+#endif
 }
 
 R_xlen_t nanoarrow_data_frame_size(SEXP x) {

Reply via email to