[Rcpp-devel] named and default arguments in exposed C++ classes

Andreas Prescher apres at kabelmail.de
Wed Mar 5 16:26:38 CET 2014


Hello,

I wrote a R package using Rcpp (0.10.4) modules
to expose my C++ classes.

All works fine, but for convenient using from R,
it would be great to use the class methods with
named arguments and default arguments.

At the moment I have to use all class methods as
declared in the corresponding C++ header files.

something like this:
RCPP_MODULE(PsiMin) {

class_<Foo>( "Foo" )
..method( "bar", &Foo::bar); }

class Foo  {

int bar(int x, int y = 2) {return x + y};
}

using from R
 > f <- new(Foo)
 > f$bar(x = 1) => 3
 > f$bar(x = 1, y = 1) => 2

I only can call my methods like this:
 > f$bar(3,4) => 7

Is there a workaround to make named/default
arguments working when using classes?

E.g. make some "mix" with 'function'
and 'class_'.

Any suggestions would be great.

Andreas






More information about the Rcpp-devel mailing list