[Rcpp-devel] C++ version of lapply using std::transform
Hello, I've just commited some code that allows iterating over generic and expression vectors (Rcpp::GenericVector and Rcpp::ExpressionVector). This allows to write for example a c++ version of lapply (without the handling of the ellipsis (...) ) using the std::transform algorithm from the STL : cpp_lapply <- cfunction(signature(x = "list", g = "function" ), ' Function fun(g) ; List input(x) ; List output( input.size() ) ; std::transform( input.begin(), input.end(), output.begin(), fun ) ; output.names() = input.names() ; return output ; ', Rcpp = TRUE, includes = "using namespace Rcpp;" ) > data <- list( x = letters, y = LETTERS, z = 1:4 ) > cpp_lapply( data, length ) $x [1] 26 $y [1] 26 $z [1] 4 Have fun ! Romain
Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/NrTG : Rcpp 0.7.5 |- http://tr.im/MPYc : RProtoBuf: protocol buffers for R `- http://tr.im/KfKn : Rcpp 0.7.2