[Rcpp-devel] A simple List example that has me stumped

Dirk Eddelbuettel edd at debian.org
Mon Sep 17 22:02:19 CEST 2012


Rodney,

With all due respect, try _minimally reproducible_ examples.  

There is still so much clutter in the example you posted that it is hard to
see the forest for the trees...

You are once again tripping over as<>() and wrap().  You _must_ use as<int>
as the following working example:

R> library(inline)
R> mcmc <- list(names=list("M", "burnin", "thin", "save"), save=list("beta", "rho", "mu", "theta"), M=2, burnin=0, thin=1)
R> f <- cxxfunction(signature(list3="ANY"), plugin="Rcpp", body='
+    Rcpp::List L3(list3);
+    int M = Rcpp::as<int>(L3["M"]);
+    return Rcpp::wrap(M);
+ ')
R> f(mcmc)
[1] 2
R> 

Not sure why mcmc needs all those layers. This works too:

R> f( list(M=42) )
[1] 42
R> 


Hth, Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com  


More information about the Rcpp-devel mailing list