| register | R Documentation |
Functions decorated with [[cpp4r::register]] in files ending in .cc,
.cpp, .h or .hpp will be wrapped in generated code and registered to
be called from R.
Note registered functions will not be exported from your package unless
you also add a @export roxygen2 directive for them.
register(path = NULL, quiet = !is_interactive(), extension = c(".cpp", ".cc"))
path |
The path to the package root directory. The default is |
quiet |
If |
extension |
The file extension to use for the generated src/cpp4r file.
|
The paths to the generated R and C++ source files (in that order).
# create a minimal package
dir <- tempfile()
dir.create(dir)
writeLines("Package: testPkg", file.path(dir, "DESCRIPTION"))
writeLines("useDynLib(testPkg, .registration = TRUE)", file.path(dir, "NAMESPACE"))
# create a C++ file with a decorated function
dir.create(file.path(dir, "src"))
writeLines("[[cpp4r::register]] int one() { return 1; }", file.path(dir, "src", "one.cpp"))
# register the functions in the package
register(dir)
# Files generated by registration
file.exists(file.path(dir, "R", "cpp4r.R"))
file.exists(file.path(dir, "src", "cpp4r.cpp"))
# cleanup
unlink(dir, recursive = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.