I'm not sure if this is what you're looking for and I don't know if
this is the official way to extract them, but if you have an object
called obj and know the name of an attribute, you can extract the
attribute using obj.attr( "attribute_name" ). You can get a vector
with all the attributes of an object with the method
obj.attributeNames(). The output of the code below shows that a
NumericMatrix has an attribute "dimnames" (if the rownames,
columnnames or both are defined).
Hope this helps,
Jelmer
library('inline')
library('Rcpp')
src <- '
Rcpp::NumericMatrix mat(a);
std::vector< std::string > attr_names = mat.attributeNames();
Rcpp::List lst( attr_names.size() );
for (int i=0;i<attr_names.size();i++) {
lst[ i ] = mat.attr( attr_names[ i ] );
}
lst.names() = attr_names;
return lst;
'
fun <- cxxfunction(signature(a="matrix"),
src, plugin="Rcpp")
mat_A <- rbind( c(1,2), c(3,2), c(5,4) )
fun( mat_A )
colnames( mat_A ) <- c("c1", "c2")
fun( mat_A )
rownames( mat_A ) <- c("r1", "r2", "r3")
fun( mat_A )
attr( mat_A, "dummy" ) <- list( "a"=1, "b"=2 ) # add dummy attribute name
fun( mat_A )
On Wed, Jun 15, 2011 at 17:45, Douglas Bates <[email protected]> wrote:
> I was looking for an extractor for the dimnames (i.e.
> R_DimNamesSymbol) from the Rcpp Matrix classes but didn't find one.
> Have I overlooked something?
> _______________________________________________
> Rcpp-devel mailing list
> [email protected]
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel