[Rcpp-devel] accessing list elements without using names

Dirk Eddelbuettel edd at debian.org
Fri Feb 10 22:30:21 CET 2012


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

-- 
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too
dark to read." -- Groucho Marx


More information about the Rcpp-devel mailing list