<div dir="ltr">Grant,<div><br></div><div>In my own work, I found that input validation is actually significantly easier to do in R. (and even if you did do it in the c++ layer, informative error messages should probably be thrown as exceptions back to R, regardless.)</div><div><br></div><div>A giant constructor is not necessary either, as you can send data and arguments to the c++ class through separate functions. This gives you some flexibility if, say, you wanted to write different R wrapper functions using the same underlying computational object.</div><div><br></div><div>My assumption, based on your original email, was that you were looking for a use case where you might want to call separate computations on different objects of class A from R (thus necessitating exposing A's functions to R), but then also be able to do some computations in an object of class B that could swap different objects of class A in and out. If that isn't the case, then there's probably a simpler, if less elegant, implementation to do what you want.</div><div><div class="gmail_extra"><br></div><div class="gmail_extra">Best,<br clear="all"><div><div>--</div>Hao Ye<br><a href="mailto:hye@ucsd.edu" target="_blank">hye@ucsd.edu</a></div>
<br><div class="gmail_quote">On Tue, Sep 9, 2014 at 6:47 PM, Grant Brown <span dir="ltr"><<a href="mailto:grant.brown73@gmail.com" target="_blank">grant.brown73@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thanks for the feedback, I'll definitely consider those options. <div><br></div><div>My original motivation (besides the sheer convenience of Rcpp modules as a way to move work into C++ land) was that there's a lot of data and model specification information that needs to migrate from R user land to the lower level library, and I didn't want the main model object to have to keep track of too much state (or have too huge of a constructor). </div><div><br></div><div>My fallback should this prove unfeasible will probably be to put  together an R layer which can collect and validate the requisite components before providing them to the giant constructor.  </div><div><br></div><div>Thanks!</div><div><br></div><div><br></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 9, 2014 at 8:16 PM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span><br>
On 9 September 2014 at 19:56, Grant Brown wrote:<br>
| Hi folks, <br>
|<br>
| I'm building several Rcpp modules which specify parts of a complicated<br>
| statistical model, and want to pass them to a main module for use. Is there an<br>
| easy way to do this? <br>
|<br>
| Below is a simplified example, with question marks where I'm not sure what to<br>
| do. I've tried accepting a pointer to A, playing with using XPtrs, and a bunch<br>
| of things which made far less sense, but so far no luck. <br>
|<br>
| Any suggestions or links to sections of the docs I should revisit would be<br>
| appreciated. <br>
<br>
</span>That's neat and somewhat ambitious. Not sure it can be done; Romain may have<br>
pointers for you.<br>
<br>
I prefer to keep things simple; at least initially.  I sometimes create a<br>
larger class (possibly as a singleton) and then have accessors from R which<br>
initialize, supply parameters, alter parameters, request computation, ... You<br>
can then play with factories, and components, and inheritance, etc pp.<br>
<br>
By keeping the interface simple I can set it up in a way which lets me test<br>
the functionality also in a simple main away from R.  But that may just be me.<br>
<br>
Dirk<br>
<div><div><br>
<br>
| Thanks,<br>
| -Grant<br>
|<br>
|<br>
| ## file: A.cpp<br>
|<br>
| class A<br>
| {<br>
| public:<br>
| A();<br>
| ~A();  <br>
| };<br>
|<br>
| class B<br>
| {<br>
| public:<br>
| B();<br>
| void DoSomethingWithInstanceOfA(???);<br>
| ~B();<br>
| };<br>
|<br>
| A::A()<br>
| {<br>
| // Do stuff<br>
| }<br>
|<br>
| B::B()<br>
| {<br>
| // Do stuff<br>
| }<br>
|<br>
| B::DoSomethingWithInstanceOfA(???)<br>
| {<br>
| // Do stuff<br>
| }<br>
|<br>
| RCPP_MODULE(mod_A)<br>
| {<br>
| using namespace Rcpp;<br>
| class_<A>( "A" )<br>
| .constructor();<br>
| }<br>
|<br>
| RCPP_MODULE(mod_B)<br>
| {<br>
| using namespace Rcpp;<br>
| class_<B>( "B" )<br>
| .constructor()<br>
| .method("DoSomethingWithInstanceOfA", &B::DoSomethingWithInstanceOfA);<br>
| }<br>
|<br>
|<br>
| ### End pseduo c++ code<br>
|<br>
|<br>
</div></div>| _______________________________________________<br>
| Rcpp-devel mailing list<br>
| <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-project.org</a><br>
| <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
<span><font color="#888888"><br>
--<br>
<a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a><br>
</font></span></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br></blockquote></div><br></div></div></div>