vector を R のリストに変換
// RcppVector.cpp #include "Rcpp.h" RcppExport SEXP foo () { std::vector<std::map<std::string,int> > v; std::map m1; std::map m2; m1["foo1"]=1; m1["bar1"]=2; m2["foo2"]=1; m2["bar2"]=2; m2["baz2"]=3; v.push_back( m1 ); v.push_back( m2 ); return Rcpp::wrap( v ); }
PKG_CXXFLAGS=$(shell Rscript -e "Rcpp:::CxxFlags()") PKG_LIBS=$(shell Rscript -e "Rcpp:::LdFlags()") CLINK_CPPFLAGS=$(shell Rscript -e "Rcpp:::Cxx0xFlags()")
というMakevarsを用意して
R CMD SHLIB RcppVector.cpp
> dyn.load ("RcppVector.so") > func <- function () { + .Call("foo") + } > (x <- - func() ) [[1]] bar1 foo1 2 1 [[2]] bar2 baz2 foo2 2 3 1 > dyn.unload ("RcppVector.so") #####