Assign attributes with C++ to an arbitrary R object?
I have started with Rcpp and I am working through Hadley's book / page
here. I guess these basics are more than enough for me, still though I
missed, some aspect or feel that this might be less basic:
How can I assign attributes to an arbitrary R Object using C++?
E.g.:
// [[Rcpp::export]]
NumericVector attribs(CharacterVector x,NumericVector y) {
NumericVector out = y;
out.attr("my-attr") = x;
return out;
}
I understand I have to specify the type in C++, but still I wonder whether
there's a way to assign an attribute to ANY R object that I pass... I have
seen that settatr in the data.table works with C++, but seems to work only
with elements of class data.table. Is there any way but writing an extra
function for every R mode / class?
No comments:
Post a Comment