<div dir="ltr">Hi Dirk, thanks for your answer.<div><br></div><div>I have checked your RcppCNPy package, but as you say, there is not methods implemented, but free functions.</div><div><br></div><div>I need to execute something like this in R:</div><div><br></div><div>R> res<-new(myClass)</div><div>R>res$myMethod(1000)</div><div><br></div><div>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?</div><div><br></div><div>Thank you again,</div><div><br></div><div>Sergio</div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-10-26 17:53 GMT+02:00 Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
On 26 October 2016 at 09:48, Sergio Bra wrote:<br>
| I am exposing a c++ class using Rcpp. It works fantastic, but my problem is how<br>
| to implement a method which has default params. I have the class:<br>
|<br>
| class myClass {<br>
|<br>
| public:<br>
| <br>
| int myMethod(int param1, int param2 = 0);<br>
| }<br>
|<br>
| and I config the module:<br>
|<br>
| RCPP_MODULE(mymodule) {<br>
| class_<myClass>("myClass")<br>
| .constructor()<br>
| .method("myMethod", &myClass::myMethod)<br>
| ;<br>
| }<br>
|<br>
| When I try to execute the function in R passing only the mandatory param I get<br>
| an error because R does not recognize the function, but if I execute it with<br>
| both params, it works great. So, how can I define the method in order to be<br>
| able to execute it without informing the optional params?<br>
<br>
</span>Hm, I have the feeling I am doing that somewhere too. Did you check existing<br>
packages with modules?<br>
<br>
I just glanced at RcppCNPy and it does it, albeit with free functions.<br>
<br>
You can definitely have multiple constructors, maybe have one with one int<br>
(defaulting value two) and one with two ints? There are subtle constraints<br>
where because of the _C_ interface so you have to 'waste' two function names<br>
on this.<br>
<br>
In sum, the easiest may be to 'hide' the module and deal with this from the R<br>
side exposing both variants from there and then just calling the one you have now.<br>
<br>
Makes sense?<br>
<span class="HOEnZb"><font color="#888888"><br>
Dirk<br>
<br>
--<br>
<a href="http://dirk.eddelbuettel.com" rel="noreferrer" target="_blank">http://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a><br>
</font></span></blockquote></div><br></div>