diff --git a/ChangeLog b/ChangeLog index 659eaf2a1..341bdc5bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2026-01-23 Dirk Eddelbuettel + + * inst/include/Rcpp/DataFrame.h (nrow): Use R_nrow() with R >= 4.6.0 + * inst/include/Rcpp/proxy/AttributeProxy.h (attributeNames): Use + R_getAttribNames() with R >= 4.6.0; + * inst/include/Rcpp/proxy/AttributeProxy.h (hasAttribute): Use + R_hasAttrib with R >= 4.6.0 + 2026-01-22 Dirk Eddelbuettel * DESCRIPTION (Version, Date): Roll micro version and date diff --git a/inst/include/Rcpp/DataFrame.h b/inst/include/Rcpp/DataFrame.h index 6e2062715..65a81576f 100644 --- a/inst/include/Rcpp/DataFrame.h +++ b/inst/include/Rcpp/DataFrame.h @@ -1,8 +1,7 @@ -// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- -// + // DataFrame.h: Rcpp R/C++ interface class library -- data frames // -// Copyright (C) 2010 - 2025 Dirk Eddelbuettel and Romain Francois +// Copyright (C) 2010 - 2026 Dirk Eddelbuettel and Romain Francois // // This file is part of Rcpp. // @@ -67,8 +66,12 @@ namespace Rcpp{ // discussed in #1430 is also possible and preferable. We also switch // to returning R_xlen_t which as upcast from int is safe inline R_xlen_t nrow() const { +#if R_VERSION < R_Version(4,6,0) Shield rn{Rf_getAttrib(Parent::get__(), R_RowNamesSymbol)}; return Rf_xlength(rn); +#else + return R_nrow(Parent::get__()); +#endif } template diff --git a/inst/include/Rcpp/proxy/AttributeProxy.h b/inst/include/Rcpp/proxy/AttributeProxy.h index 1fbc40314..f3e31466f 100644 --- a/inst/include/Rcpp/proxy/AttributeProxy.h +++ b/inst/include/Rcpp/proxy/AttributeProxy.h @@ -80,13 +80,11 @@ class AttributeProxyPolicy { std::vector attributeNames() const { std::vector v; #if R_VERSION >= R_Version(4, 6, 0) - auto visitor = [](SEXP name, SEXP attr, void* data) -> SEXP { - std::vector* ptr = static_cast*>(data); - std::string s{CHAR(Rf_asChar(name))}; - ptr->push_back(s); - return NULL; - }; - R_mapAttrib(static_cast(*this).get__(), visitor, static_cast(&v)); + SEXP attrs = R_getAttribNames( static_cast(*this)); + R_xlen_t n = XLENGTH(attrs); + for (R_xlen_t i = 0; i < n; i++) { + v.push_back(std::string(CHAR(STRING_ELT(attrs, i)))); + } #else SEXP attrs = ATTRIB( static_cast(*this).get__()); while( attrs != R_NilValue ){ @@ -98,7 +96,11 @@ class AttributeProxyPolicy { } bool hasAttribute(const std::string& attr) const { +#if R_VERSION >= R_Version(4, 6, 0) + return R_hasAttrib(static_cast(*this).get__(), Rf_install(attr.c_str())); +#else return static_cast(*this).attr(attr) != R_NilValue; +#endif }