That is great example of why folks should NOT use the .C() interface. Rcpp can help here, __even if you do not use any Rcpp language features__. Below is a showcase for the recent sourceCpp() function which takes a C++ file (shown below), converts it and optionally runs the embedded R code. Think of as something like Sweave for mixing C++ and R rather than Latex and R.
Source file is shown via cat on the cmdline: edd@max:/tmp$ cat dblvec.cpp #include <Rcpp.h> #include <vector> // [[Rcpp::export]] std::vector<double> dbl(std::vector<double> x) { std::vector<double> y(x.size()); for (unsigned int i=0; i<y.size(); i++) y[i] = 2.0*x[i]; return y; } /*** R myx <- seq(1.1, 5.5, by=1.1) print(dbl(myx)) ***/ edd@max:/tmp$ edd@max:/tmp$ We then simply source it to show off how it transform a C++ vector of doubles: edd@max:/tmp$ R --quiet -e 'library(Rcpp); sourceCpp("dblvec.cpp")' R> library(Rcpp); sourceCpp("dblvec.cpp") R> myx <- seq(1.1, 5.5, by = 1.1) R> print(dbl(myx)) [1] 2.2 4.4 6.6 8.8 11.0 R> R> edd@max:/tmp$ No make, compiler invocation, linking, ... which all happen behind the scenes. We just enjoy the C++ function to double the content of a double vector. Hope this helps, Dirk -- Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel