For performance reasons, I'm working on implementing one of the functions in my R package at the C level using R's .Call
. interface. I'd like my C function to be able to use some of the already existing C functions defined in another package (network
) to access and manipulate data structures. However, I'm a C newbie, and I have not been able to figure out how to correctly set up / modify the C function registration in network
and the import definitions in my package so that I can directly call the C code without creating a duplicate copy of the code in my package.
The CRAN documentation
https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Linking-to-native-routines-in-other-packages seems to say that cross-package linking is possible, and that the lme4
and Matrix
packages provide an example. (I can find the R_RegisterCCallable
in Matrix
's init.c file, but I have not been able to locate the corresponding R_GetCCallable
calls in lme4
.)
Perhaps the step I'm missing is the correct portable way to import the API header from network/inst/include into my package's C src?
My question is very closely related to the following three, but the solutions seem to all use Rcpp, and so seem to gloss over the import definition step (probably because it is obvious to everyone except a C newbie like me).
using C function from other package in Rcpp
How do I share C++ functions in Rcpp-based libraries between R packages?