0
votes

I'm trying to export C++ functions from my R package 'TreeTools' so they can be called from a different package. I've added the line

// [[Rcpp::interfaces(r, cpp)]]

to src/renumber_tree.cpp, per [https://dirk.eddelbuettel.com/code/rcpp/Rcpp-attributes.pdf / http://r-pkgs.had.co.nz/src.html] and when I compileAttributes() and document() the package, there are indicators that the export has been acknowledged:

  • Relevant header files are added to inst/includes;
  • #include "../inst/include/TreeTools.h" is added to the start of RcppExports.cpp
  • A function RcppExport SEXP _TreeTools_RcppExport_registerCCallable() is added to the end of RcppExports.cpp

Compliation nevertheless fails with

Error in .Call("_TreeTools_RcppExport_registerCCallable", PACKAGE = "TreeTools") : 
  "_TreeTools_RcppExport_registerCCallable" not available for .Call() for package "TreeTools"

Can anyone help me to debug this error? Could it be related to the fact that I have a manually-generated PACKAGE-init.c file?

1
Ensure you run compileAttributes() when you (re-)define interface. I was just using this on a package the other day and corresponding glue is generated. Make sure all files are updated, what you show leads me to suspect one was left behind. - Dirk Eddelbuettel
And of course double-check that the symbols requested are present, including in the "setup" bits typically at the bottom of src/RcppExports.cpp. Also, and this may sound like extra work, maybe test the basic functionality on a one-function ad-hoc package. - Dirk Eddelbuettel

1 Answers

0
votes

Thanks, Dirk, for pointing me in the right direction.

To TreeTools-init.C, I needed to add

extern SEXP _TreeTools_RcppExport_registerCCallable();

and

static const R_CallMethodDef callMethods[] = {
  &_TreeTools_RcppExport_registerCCallable, 0},
  {NULL, NULL, 0}
};

In RcppExports.R, I saw

# Register entry points for exported C++ functions
methods::setLoadAction(function(ns) {
    .Call('_TreeTools_RcppExport_registerCCallable', PACKAGE = 'TreeTools')
})

Replacing the straight quotes around '_TreeTools_RcppExport_registerCCallable' with backticks, i.e.

`_TreeTools_RcppExport_registerCCallable`

allowed the package to load.

Of course, these are replaced with straight quotes whenever compileAttributes() is run, so this doesn't feel like a complete solution...