[Rcpp-devel] Using an Rcpp module package in an R Reference Class

Christian Gunning xian at unm.edu
Tue Oct 14 09:29:29 CEST 2014


Dear all,

I have a working package that uses the Rcpp module mechanism (my
RaggedArray project, as per previous discussion), and a working pure-R
reference class (RefClass) that does computation on a list-based
ragged array.  I'm unsure on how to integrate the RaggedArray module
into the RefClass. I have a simple example working, but I'm getting
inscrutable "expecting an external pointer" errors every time I try
something non-trivial. Is there a canonical way to do this, or a good
example floating about?

I've looked both at direct inheritance:
## but how to initialize the base class?
wormSim <- setRefClass("wormSim",
    contains='RaggedArray', ## parent class
    fields=c( CF="numeric")
)

and at adding a field:
##
wormSim <- setRefClass("wormSim",
    fields=c( CF="numeric", LL = "RaggedArray")
)

On a seemingly related note, I'm having trouble figuring out the
details of exporting / exposing an Rcpp module to R via standard
tools.  I've found the following related items, but I'm still confused
about how they're related.  Are any of these S4-related rather than
RefClass related?  Any pointers/docs/examples would be appreciated.

* Rcpp: RCPP_EXPOSED_CLASS_NODECL(RaggedArray)
* Rcpp: setRcppClass("RaggedArray")
* roxygen2/NAMESPACE:  @exportClass RaggedArray

Thanks,
Christian


More information about the Rcpp-devel mailing list