I am making an R package in Rstudio and I selected the option Configure Build Tools > Configure
and select Use roxygen to generate NAMESPACE
. I wrote my functions in Rcpp and this is what the NAMESPACE
looks like when I generate it with roxygen2
:
# Generated by roxygen2 (4.1.1): do not edit by hand
export(function1)
export(function2)
export(function3)
export(function4)
Since my functions are written with Rcpp, which I then export, then they will used in R via .Call
. However, from writing R extensions we should use useDynLib()
in such a case. This is why I think I am getting an error when I try to call function1
and the error is:
Error in .Call("Mypackage_function1", PACKAGE = "Mypackage", var1, :
"Mypackage_function1" not available for .Call() for package "Mypackage"
When I use the default NAMESPACE
when I start a project in Rstudio, I have the following in NAMESPACE
:
useDynLib(packagename)
exportPattern("^[[:alpha:]]+")
importFrom(Rcpp, evalCpp)
When I use the default NAMESPACE
I can call the functions using .Call
however I get a warning when I check the package that I am not generating the NAMESPACE
using roxygen.
Is there a fix for this? Any advice is appreciated.
This is unrelated to the usage of RStudio: For Roxygen to generate the relevant useDynLib
specification, you need to use the @useDynLib
tag in a Roxygen doc comment:
#' @useDynLib packagename
You can do this anywhere (where you can use normal Roxygen comments) but it makes sense to put this into the package documentation, rather than the documentation of a specific function. Usually this resides in a file called R/packagename-package.r
:
#' My package documentation
#' … bla bla …
#' @name packagename
#' @docType package
#' @useDynLib packagename
NULL
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments