[Rcpp-devel] constructor with many parameters in Rcpp module

andre zege andre.zege at gmail.com
Tue Nov 1 02:14:15 CET 2011

Hi everybody, my apologies in advance if i missed something obvious in
documentation or misinterpreted things. I started  experimenting with Rcpp
modules and it seems to do in simpler cases exactly what i need. However, I
am stuck on something that is probably very common

I am using the class for which constructor has 11 parameters, some of which
are pointers to doubles.

Strategy s(double *, double *, double *, double *, double *, int, int, int,
double, double, double)

Pointers  point to memory containing matrices that armadillo code inside
the class Strategy works works with. According to what i read in rcpp
module docs, a class could be defined in rcpp module only if constructor
has six or less parameters. So it seems that the only way for me to use the
class from R is to write a Rcpp function that would get called from R with
a signature

RcppExport void helper(SEXP, SEXP, ...., SEXP){

//convert input parameters

Strategy s(....);

//do whatever needs to be done in Strategy


and  call constructor  within C++ code and then return to R. Is this the
best way to use Rcpp  things in my circumstance?

Also, if i take this approach, how  would I pass pointers to double to a
C++ constructor? It seems i need to convert SEXP that i receive from R to
double * in Rcpp framework -- it seems that as<>() template wouldn't
convert to a pointer.  I could use of course .C interface, but i wanted to
use Rcpp for a number  of C++ classes in a uniform way, regardless of the
number of parameters in the constructor.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20111031/f5f914a4/attachment.htm>

More information about the Rcpp-devel mailing list