How to register native routines with Rcpp?

c++, r, rcpp

Solution

I finally managed to register the native routines with Rcpp and passed BiocCheck. I am using Rcpp 0.12.9, BiocCheck 1.9.3 and Kmisc 0.5.1.

1) In the automatically by Rcpp generated file "RcppExports.cpp", add "// [[register]]" before each function in the following place:

// my_function
returntype my_function(...);
// [[register]]
RcppExport SEXP packagename_my_function(...) {
BEGIN_RCPP
...
END_RCPP
}

2) Then, from R, run

Kmisc::registerFunctions(prefix="")

This will create a file "packagename_init.c"

3) Make sure you have

useDynLib(packagename, .registration=TRUE)

in your NAMESPACE file. It also worked without the .registration=TRUE for me. This should be sufficient to pass BiocCheck. You can check the registered routines with

getDLLRegisteredRoutines("packagename")

Problem

I am writing a Bioconductor package. In order to do that, it needs to pass BiocCheck. I am using Rcpp and Rstudio to make c++ code available to R using the tag `//[[Rcpp::export]]` and Rcpp classes and not SEXP ones. Rstudio generates Rcpp_export.cpp and Rcpp_export.R automatically and it works fine. However, BiocCheck complains about it: Checking native routine registration.. Register native routines! see http://cran.r-project.org/doc/manuals/R-exts.html#Registering-native-routines So, anybody knows how to solve this?

Original source