Origin of the Registration Issue: the NAMESPACE
file
I'm assuming that in your NAMESPACE
file you have:
exportPattern("^[[:alpha:]]+")
This basically "automatically" exports any function that begins with alphabet letter. Thus, your exported Rcpp function via // [[Rcpp::exports]]
is being picked up.
To solve this, there are two solutions. The first is more of a "hack" and the second involves properly using export()
in the NAMESPACE
file.
Custom Naming the Rcpp Function
For the first solution, you can change how you export the Rcpp function explicitly stating how the function should appear in R. The important aspect of this name change, due to the configuration of the NAMESPACE
registering all functions that start with an alphabetic letter, is to prefix to the function name a period (.
), e.g.:
// [[Rcpp::export(".function_name")]]
As a real life example, take the function C++ function some_function()
:
// [[Rcpp::export]]
void some_function(int value)
The use of the Rcpp attributes here will export into R the function name some_function()
Now, to explicitly name the function something different for R would be:
// [[Rcpp::export(.some_function)]]
void some_function(int value)
which will be exported into R as .some_function()
. Probably more illustrative is we could change it to be a completely different name, e.g.
// [[Rcpp::export(toad)]]
void some_function(int value)
This would mean the exported R function that calls the C++ function is toad()
.
Specify exports
The other approach that you may wish to take is to explicitly declare which function should be exported and which function should not be exported. To do this, the NAMESPACE
file must be rid of the exportPattern("^[[:alpha:]]+")
entry and each function that should be available must be specified as export(function)
. For example, the cIRT
package's NAMESPACE
has each function that should be "public" exported.
With this being said, a majority of users generate documentation with roxygen2
. Under this documentation generator, you can specify in the roxygen2
tags, e.g. #' @tag
or //' @tag
, that the function should be exported into the NAMESPACE
with:
# R code
#' @export
or
// C++ code
//' @export
Within the function documentation for C++ this would look like:
//' Title
//'
//' Description
//'
//' @export
If you do not want a function exported, then all you have to do is not document it with //' @export
.
:::
? – Mackenie