You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As part of clarifying and tightening the R API for packages the
non-API entry points ATTRIB and SET_ATTRIB will be removed from
installed header files and, where possible, hidden from package
access. Both expose internal structure that might need to be changed
and also make it too easy to inadvertently break consistency
assumptions about the values of some attributes. Using these
functions is will now result in check NOTEs. These check NOTEs will
soon be replaced by WARNINGs; this will probably happen by the end of
January. The 'Working with attributes' section in the 'Writing R
Extensions' list some alternatives. Additional functions for working
with attributes, without exposing internal attributes structure, could
be added if they are needed.
Below is a first minimal version of retrieving all attribute names from a given SEXP.
#include<Rcpp/Lighter>// [[Rcpp::export]]
std::vector<std::string> getnamesPrevious(SEXP s) {
std::vector<std::string> v ;
SEXP attrs = ATTRIB( s ); //static_cast<const CLASS&>(*this).get__());while( attrs != R_NilValue ){
v.push_back( std::string(CHAR(PRINTNAME(TAG(attrs)))) ) ;
attrs = CDR( attrs ) ;
}
return v;
}
extern"C"SEXPwalk(SEXP tag, SEXP attr, void* data) {
std::vector<std::string>* vecptr = static_cast<std::vector<std::string>*>(data);
std::string s{Rcpp::as<std::string>(Rf_asChar(tag))};
vecptr->push_back(s);
returnNULL;
}
/* Map a function FUN over an object's attributes. FUN should return NULL if it wants the iteration to continue. A non-NULL return value from FUN terminates the iteration and is returned as the value of the R_mapAttrib call.*/// SEXP R_mapAttrib(SEXP x, SEXP (*FUN)(SEXP, SEXP, void *), void *data);// [[Rcpp::export]]
std::vector<std::string> getnamesNew(SEXP s) {
std::vector<std::string> v;
R_mapAttrib(s, walk, (void *) &v);
return v;
}
/*** RsuppressMessages(library(xts))x <- xts(1:4, Sys.Date()+0:3) # as an xts has three attributesgetnamesPrevious(x)getnamesNew(x)*/
On Sun, 21 Dec 2025, Dirk Eddelbuettel wrote:
[673121?s=20&v=4] eddelbuettel left a comment (RcppCore/Rcpp#1429)
This extends also to testing if a given string is among the attributes.
I will probably add R_getAttribNames and R_getAttribCount to cover
some common uses. We could also add R_existsAttrib, or
(Rf_)existsAttribute as well.
Is there a reason you don't use the dim attribute for this, as the
R-level nrow() does?
The comment is no longer accurate as the returned expanded row.names
now uses a compact integer sequence.
[This compact row names representation is the main reason I am not
sure the current R_mapAttrib is quite what we want. There is also the
peculiar handling of names on one-dimensional arrays and
pairlist/language objects...]
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you werementioned.[AA55UVGQUYBAAU5KFDIMWQT4C2ZBVA5CNFSM6AAAAACPT6SYIOWGG33NNVSW45C7
OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTW3I4QWC.gif] Message ID:
***@***.***>
--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa Phone: 319-335-3386
Department of Statistics and Fax: 319-335-3017
Actuarial Science
241 Schaeffer Hall email: ***@***.***
Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu
I just worked out a solution using R_mapAttrib() that is close to what we currently do. It covers the compact way, and falls back to LENGTH if need be. To minimise impact I was just following the old logic.
But I also scratched my chin and wondered why we do that in the first place. It is a pretty old routine too. Looking at dim() sounds like a viable alternative.
dim(() for a data.frame object dispatches to internal function shortRowNames() which is implemented via another internal function do_shortRowNames() which accesses attributes in ways we cannot, and implements similar logic. What I just sketched is similar (following the existing function).
Activity
eddelbuettel commentedon Dec 20, 2025
WRE is a little minimal on all of this, see 6.22.6 Working with Attributes.
Below is a first minimal version of retrieving all attribute names from a given SEXP.
Seems to work with (very current) R-devel:
eddelbuettel commentedon Dec 21, 2025
This extends also to testing if a given string is among the attributes.
But I am less sure I know how to avoid the third use:
Rcpp/inst/include/Rcpp/DataFrame.h
Lines 63 to 84 in 9778196
ltierney commentedon Dec 21, 2025
eddelbuettel commentedon Dec 21, 2025
I just worked out a solution using
R_mapAttrib()that is close to what we currently do. It covers the compact way, and falls back to LENGTH if need be. To minimise impact I was just following the old logic.But I also scratched my chin and wondered why we do that in the first place. It is a pretty old routine too. Looking at
dim()sounds like a viable alternative.eddelbuettel commentedon Dec 21, 2025
dim(()for adata.frameobject dispatches to internal functionshortRowNames()which is implemented via another internal functiondo_shortRowNames()which accesses attributes in ways we cannot, and implements similar logic. What I just sketched is similar (following the existing function).