r-lib / cpp11

cpp11 helps you to interact with R objects using C++ code.
https://cpp11.r-lib.org/
Other
199 stars 46 forks source link

Creating R package with cpp11 #233

Closed maximiliank closed 2 years ago

maximiliank commented 3 years ago

I was following the documentation to create an R package using cpp11. I could create and install the package but could not call any functions until I figured out that I had to create export statements in the NAMESPACE file.

Once I added the export statements as comment to R/pkgname-package.R it works, e.g.

#' @useDynLib pkgname, .registration = TRUE
#' @export vacc3
#' @export vacc3a
NULL

I also hat to put NULL in the end, otherwise nothing is picked up in the documentation step.

Can you update the documentation to mention the export statements? Or would it be possible that cpp11::cpp_register() also creates them?

jimhester commented 3 years ago

Generally we write R wrapper functions around the cpp11 registered C++ functions, as often there is additional processing and argument checking needed that is easier to do in R than C++.

maximiliank commented 3 years ago

I see. Would still be good to add a note about the exports to the package section.