As @RalfStubner pointed out in the comments, the NAMESPACE
file is meant for exporting and importing R functions and data.
The primary requirement for a NAMESPACE
files in a package using Rcpp is to ensure:
- A single function from Rcpp package is imported for registration reasons.
- Generally, either
evalCpp
or sourceCpp
is used.
- Provide the name of the shared object via
useDynLib()
,
- This is the name of the R package being built.
importFrom(Rcpp, sourceCpp)
useDynLib(<PACKAGE_NAME_HERE>, .registration = TRUE)
where <PACKAGE_NAME_HERE>
is the name of the package without <>
.
If you're interested in using headers to share code between R packages, consider looking at:
https://github.com/r-pkg-examples/rcpp-shared-cpp-functions
The main design pattern is using inst/include
directory to place a header-only library. Then, in src/
write bindings to the library. Ensure that src/Makevars
and src/Makevars.win
has:
# Register where the header files for the package can be found
PKG_CXXFLAGS=-I../inst/include/
If you want to share function definitions between .cpp
files in the same R package, see:
https://github.com/r-pkg-examples/rcpp-headers-src
This avoids a single monolithic .cpp
file, but does not allow for sharing the compiled code routines between R packages outside of the exported R wrapper.