Hi Dirk, thanks for your answer. I have checked your RcppCNPy package, but as you say, there is not methods implemented, but free functions.
I need to execute something like this in R: R> res<-new(myClass) R>res$myMethod(1000) So, when you say that I can manage it from the R side, are you talking about programming that behaviour in a *.R file? In case of an affirmative answer, same file where I have the loadModule sentence? Thank you again, Sergio 2016-10-26 17:53 GMT+02:00 Dirk Eddelbuettel <e...@debian.org>: > > 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