<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>Hi.  I would like to start using Rcpp modules in my code, but I am having some trouble loading them into R.  Here is an example:</div><div><br></div><div>#include <Rcpp.h></div><div><br></div><div>template<typename T></div><div>class adding {</div><div><br></div><div> public:</div><div>  const T a, b;</div><div>  adding(const T&, const T&);</div><div>  T add2();</div><div><br></div><div>};</div><div><br></div><div>template<typename T></div><div>adding<T>::adding(const T& a_, const T& b_) : a(a_), b(b_) {}</div><div><br></div><div>template<typename T></div><div>T adding<T>::add2() {</div><div><br></div><div>  T res = a + b;</div><div>  return(res);</div><div>}</div><div><br></div><div>RCPP_MODULE(adding){</div><div><br></div><div>  Rcpp::class_< adding<double> >("adding")</div><div>    .constructor<double, double>()</div><div>    .method("add2",&adding<double>::add2)</div><div>    ;</div><div>}</div></div><div><br></div><div><br></div><div>Then, in R, I do this:</div><div><br></div><div>library(Rcpp)</div><div>dyn.load("add.so")</div><div>mod <- Module("adding")</div><div>mod</div><div><br></div><div>The result is:</div><div><br></div><div>Uninitialized module named "adding" from package ".GlobalEnv"</div><div><br></div><div><br></div><div>I also tried adding a PACKAGE argument, such as PACKAGE = "add.so", to no avail.  So I am wondering if it is possible to use Rcpp modules with self-compiled code, outside of the R package structure (I believe I have good reasons for doing this).  The library may also include other C++ functions that are loaded with no problem.  It's just the module that is not recognized.</div><div><br></div><div>Thanks in advance for any suggestions.</div><div><br></div><div>Michael</div><div><br></div><div><br></div><div><br></div><div><br></div><br><div apple-content-edited="true">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>-------------------------------------------<br>Michael Braun<br>Associate Professor of Management Science<br>MIT Sloan School of Management<br>100 Main St.., E62-535<br>Cambridge, MA 02139<br><a href="mailto:braunm@mit.edu">braunm at mit.edu</a><br><br></div><div><br></div></div><br class="Apple-interchange-newline"><br class="Apple-interchange-newline">
</div>
<br></body></html>