[Rcpp-devel] Method with default params using RCPP_MODULE
Sergio Bra
sergio.bra88 at gmail.com
Wed Oct 26 18:24:54 CEST 2016
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 <edd at 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 | edd at debian.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20161026/a19935d6/attachment.html>
More information about the Rcpp-devel
mailing list