[Rcpp-devel] Loading Rcpp modules from dynamic library
Michael Braun
braunm at MIT.EDU
Sat Feb 25 20:45:55 CET 2012
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:
#include <Rcpp.h>
template<typename T>
class adding {
public:
const T a, b;
adding(const T&, const T&);
T add2();
};
template<typename T>
adding<T>::adding(const T& a_, const T& b_) : a(a_), b(b_) {}
template<typename T>
T adding<T>::add2() {
T res = a + b;
return(res);
}
RCPP_MODULE(adding){
Rcpp::class_< adding<double> >("adding")
.constructor<double, double>()
.method("add2",&adding<double>::add2)
;
}
Then, in R, I do this:
library(Rcpp)
dyn.load("add.so")
mod <- Module("adding")
mod
The result is:
Uninitialized module named "adding" from package ".GlobalEnv"
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.
Thanks in advance for any suggestions.
Michael
-------------------------------------------
Michael Braun
Associate Professor of Management Science
MIT Sloan School of Management
100 Main St.., E62-535
Cambridge, MA 02139
braunm at mit.edu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20120225/b5142d07/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1844 bytes
Desc: not available
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20120225/b5142d07/attachment.bin>
More information about the Rcpp-devel
mailing list