Skip to content

Commit 7c1e5b4

Browse files
authored
Update three more uses of attribute getting for R 4.6.0 or later (#1450)
1 parent 2c5240c commit 7c1e5b4

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2026-01-23 Dirk Eddelbuettel <edd@debian.org>
2+
3+
* inst/include/Rcpp/DataFrame.h (nrow): Use R_nrow() with R >= 4.6.0
4+
* inst/include/Rcpp/proxy/AttributeProxy.h (attributeNames): Use
5+
R_getAttribNames() with R >= 4.6.0;
6+
* inst/include/Rcpp/proxy/AttributeProxy.h (hasAttribute): Use
7+
R_hasAttrib with R >= 4.6.0
8+
19
2026-01-22 Dirk Eddelbuettel <edd@debian.org>
210

311
* DESCRIPTION (Version, Date): Roll micro version and date

inst/include/Rcpp/DataFrame.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2-
//
1+
32
// DataFrame.h: Rcpp R/C++ interface class library -- data frames
43
//
5-
// Copyright (C) 2010 - 2025 Dirk Eddelbuettel and Romain Francois
4+
// Copyright (C) 2010 - 2026 Dirk Eddelbuettel and Romain Francois
65
//
76
// This file is part of Rcpp.
87
//
@@ -67,8 +66,12 @@ namespace Rcpp{
6766
// discussed in #1430 is also possible and preferable. We also switch
6867
// to returning R_xlen_t which as upcast from int is safe
6968
inline R_xlen_t nrow() const {
69+
#if R_VERSION < R_Version(4,6,0)
7070
Shield<SEXP> rn{Rf_getAttrib(Parent::get__(), R_RowNamesSymbol)};
7171
return Rf_xlength(rn);
72+
#else
73+
return R_nrow(Parent::get__());
74+
#endif
7275
}
7376

7477
template <typename T>

inst/include/Rcpp/proxy/AttributeProxy.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,11 @@ class AttributeProxyPolicy {
8080
std::vector<std::string> attributeNames() const {
8181
std::vector<std::string> v;
8282
#if R_VERSION >= R_Version(4, 6, 0)
83-
auto visitor = [](SEXP name, SEXP attr, void* data) -> SEXP {
84-
std::vector<std::string>* ptr = static_cast<std::vector<std::string>*>(data);
85-
std::string s{CHAR(Rf_asChar(name))};
86-
ptr->push_back(s);
87-
return NULL;
88-
};
89-
R_mapAttrib(static_cast<const CLASS&>(*this).get__(), visitor, static_cast<void*>(&v));
83+
SEXP attrs = R_getAttribNames( static_cast<const CLASS&>(*this));
84+
R_xlen_t n = XLENGTH(attrs);
85+
for (R_xlen_t i = 0; i < n; i++) {
86+
v.push_back(std::string(CHAR(STRING_ELT(attrs, i))));
87+
}
9088
#else
9189
SEXP attrs = ATTRIB( static_cast<const CLASS&>(*this).get__());
9290
while( attrs != R_NilValue ){
@@ -98,7 +96,11 @@ class AttributeProxyPolicy {
9896
}
9997

10098
bool hasAttribute(const std::string& attr) const {
99+
#if R_VERSION >= R_Version(4, 6, 0)
100+
return R_hasAttrib(static_cast<const CLASS&>(*this).get__(), Rf_install(attr.c_str()));
101+
#else
101102
return static_cast<const CLASS&>(*this).attr(attr) != R_NilValue;
103+
#endif
102104
}
103105

104106

0 commit comments

Comments
 (0)