Functions decorated with [[cpp11::register]]
in files ending in .cc
,
.cpp
, .h
or .hpp
will be wrapped in generated code and registered to
be called from R.
cpp_register(path = ".", quiet = FALSE)
path | The path to the package root directory |
---|---|
quiet | If |
The paths to the generated R and C++ source files (in that order).
In order to use cpp_register()
the cli
, decor
, desc
, glue
,
tibble
and vctrs
packages must also be installed.
# 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("[[cpp11::register]] int one() { return 1; }", file.path(dir, "src", "one.cpp")) # register the functions in the package cpp_register(dir)#>#> ✔ generated file cpp11.R#> ✔ generated file cpp11.cpp#> [1] TRUE#> [1] TRUE