@@ -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