> > In sum, the easiest may be to 'hide' the module and deal with this from > the R > side exposing both variants from there and then just calling the one you > have now.
I agree - though I don't think you even need two variants of the C++ function if there's an R function to handle default arguments. Best, -- Hao Ye h...@ucsd.edu On Wed, Oct 26, 2016 at 8:53 AM, Dirk Eddelbuettel <e...@debian.org> wrote: > > On 26 October 2016 at 09:48, Sergio Bra wrote: > | I am exposing a c++ class using Rcpp. It works fantastic, but my problem > is how > | to implement a method which has default params. I have the class: > | > | class myClass { > | > | public: > | > | int myMethod(int param1, int param2 = 0); > | } > | > | and I config the module: > | > | RCPP_MODULE(mymodule) { > | class_<myClass>("myClass") > | .constructor() > | .method("myMethod", &myClass::myMethod) > | ; > | } > | > | When I try to execute the function in R passing only the mandatory param > I get > | an error because R does not recognize the function, but if I execute it > with > | both params, it works great. So, how can I define the method in order to > be > | able to execute it without informing the optional params? > > Hm, I have the feeling I am doing that somewhere too. Did you check > existing > packages with modules? > > I just glanced at RcppCNPy and it does it, albeit with free functions. > > You can definitely have multiple constructors, maybe have one with one int > (defaulting value two) and one with two ints? There are subtle > constraints > where because of the _C_ interface so you have to 'waste' two function > names > on this. > > In sum, the easiest may be to 'hide' the module and deal with this from > the R > side exposing both variants from there and then just calling the one you > have now. > > Makes sense? > > Dirk > > -- > http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org > _______________________________________________ > Rcpp-devel mailing list > Rcpp-devel@lists.r-forge.r-project.org > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel >
_______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel