[Rcpp-devel] class methods and R_RegisterCCallable
Serguei Sokol
serguei.sokol at gmail.com
Thu Oct 24 16:01:33 CEST 2019
Hi,
I'am trying to find a way to access class methods of one Rcpp package
(say pkgM) from C++ code in another one (say pkgA).
If it were simple C++ routines and not class methods, the way is known
and even automatized. E.g. if I generate pkgM with
Rcpp::Rcpp.package.skeleton("pkgM", module=TRUE)
Rcpp::compileAttributes("pkgM")
then in pkgM/src/RcppExports.cpp we can see
static const R_CallMethodDef CallEntries[] = {
{"_pkgM_rcpp_hello_world", (DL_FUNC) &_pkgM_rcpp_hello_world, 0},
...
As far as I understand, it registers _pkgM_rcpp_hello_world for use with
R_GetCCallable from other packages. And it is a consequence of preceding
rcpp_hello_world() with "// [[Rcpp::export]]".
If I add "// [[Rcpp::interfaces(r, cpp)]]" in pkgM/src/rcpp_module.cpp
it produces pkgM/inst/include/{pkgM.h,pkgM_RcppExports.h} and
static const R_CallMethodDef CallEntries[] = {
...
{"_pkgM_RcppExport_registerCCallable", (DL_FUNC)
&_pkgM_RcppExport_registerCCallable, 0},
...
but still nothing for methods and functions from RCPP_MODULE.
So my question, what is a canonical way (if defined) to expose class
methods (via RCPP_MODULE or any other mechanism) in such a way that they
become callable from C++ code of another package? Am I supposed to
register them manually in some way using
_pkgM_RcppExport_registerCCallable()? And if so, how can I retrieve them
in C++ code of another package?
Thanks,
Serguei.
More information about the Rcpp-devel
mailing list