Skip to content
Prev 3421 / 10988 Next

[Rcpp-devel] accessing list elements without using names

On 10 February 2012 at 15:05, Douglas Bates wrote:
| Or if you want to show off you could collapse it to
| 
| > src <- "
| +   NumericMatrix tmpMatrix(as<SEXP>(List(L)[0]));
| +   return wrap(tmpMatrix.ncol());
| + "
| > f <- cxxfunction(signature(L="list"), src, plugin = "Rcpp" )
| > f(list(matrix(1:9,3,3)))
| [1] 3

Nice. The as<> cast is a good idea, it may even work with as<NumericMatrix>
which would avoid the ugly SEXP in user code ...

Dirk