Skip to content
Prev 3419 / 10988 Next

[Rcpp-devel] accessing list elements without using names

Another approach is to force the evaluation of the list element with as<SEXP>
+   List inputList(L) ;
+   NumericMatrix tmpMatrix(as<SEXP>(inputList[0])) ;
+
+   return wrap(tmpMatrix.ncol());
+ "
[1] 3

In answer to Sameer's follow-up question of why it doesn't work
directly to form the NumericMatrix from the list element, try reading
the code.  It's complicated.  R is an untyped language with an
underlying generic structure called an SEXPREC whereas C++ is a
strongly typed language.  It is not always possible to map an
amorphous untyped object to a particular data structure without going
through a lot of template magic.  Template meta-programming is not for
the faint of heart.
On Fri, Feb 10, 2012 at 2:10 PM, Dirk Eddelbuettel <edd at debian.org> wrote: