[Rcpp-devel] Function arguments to R

2015-05-03 Thread Sören Vogel
Hello I have created a function that I want to expose to R in my package using Rcpp modules: #include using namespace Rcpp; void myfun( Rcpp::List lst, NumericVector vec ) { // do something } RCPP_MODULE(mymod) { function("myfun", &myfun, "Does something."); } The documentation

Re: [Rcpp-devel] List of Lists to List of Vectors

2015-05-03 Thread Tim Keitt
Here's a really bare-bones version. Not very pretty or complete, but it does do the job. Could the 'unlist' part be converted to Rcpp? THK library(Rcpp) code = ' SEXP test(List a) { int l = Rf_length(a[0]); typedef std::vector svec; std::vector x(l); for (int i = 0; i != l; ++i) for

[Rcpp-devel] Function arguments to R

2015-05-03 Thread soeren . vogel
(Repost due to wrong mail AD.) Hello I have created a function that I want to expose to R in my package using Rcpp modules: #include using namespace Rcpp; void myfun( Rcpp::List lst, NumericVector vec ) { // do something } RCPP_MODULE(mymod) { function("myfun", &myfun, "Does so

Re: [Rcpp-devel] List of Lists to List of Vectors

2015-05-03 Thread Tim Keitt
A slightly improved version: library(Rcpp) code = ' SEXP test(List a) { auto l = Rf_length(a[0]); using svec = std::vector; std::vector x(l); for (List b : a) { if (b.size() != l) stop("Ragged input"); for (int i = 0; i != l; ++i) x[i].push_back(b[i]); } return w

Re: [Rcpp-devel] Function arguments to R

2015-05-03 Thread Dirk Eddelbuettel
On 3 May 2015 at 16:41, Sören Vogel wrote: | Hello | | I have created a function that I want to expose to R in my package using Rcpp modules: | | #include | using namespace Rcpp; | void myfun( Rcpp::List lst, NumericVector vec ) { | // do something | } | RCPP_MODULE(mymod) { | func

Re: [Rcpp-devel] List of Lists to List of Vectors

2015-05-03 Thread Antonio Piccolboni
Check here for something similar to Tim's solution that preallocates all vectors to avoid the costly push_back. Still needs the unlists in R, so it's expensive in that dimension, the number of lists in the output. Antoni