[R] Rcpp module / class access -- answer

Pascal A. Niklaus Pascal.Niklaus at ieu.uzh.ch
Tue Mar 3 16:35:47 CET 2015


Hi all,

I am trying to answer my own question (although it probably does not end 
up in the thread because I am not a subscribed and thus have to send a 
new mail).


The way I finally got the code working was:


In NAMESPACE, comment out the following lines

# importFrom(Rcpp, loadModule)
# importFrom(Rcpp, evalCpp)



In zzz.R:

# loadModule("mod_yada",TRUE);

.pkgNamespace <- environment()

.onLoad <- function(libname, pkgname) {
   assign("mod_yada",
   Module("mod_yada",PACKAGE="testPackage",mustStart=TRUE),
   envir=.pkgNamespace);
}


The object generation then works as expected in the S4 class code.

Not sure whether this is the best way to achieve this, though.

Pascal



More information about the R-help mailing list