Skip to content

Commit 258fb05

Browse files
authored
Expand docs / example for routine registration (#2151)
Fixes #1501
1 parent ad3a9d3 commit 258fb05

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

R/test-compiled-code.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,28 @@ run_cpp_tests <- function(package) {
257257
#' run_testthat_tests
258258
#' }
259259
#'
260+
#' Assuming you have `useDynLib(<pkg>, .registration = TRUE)` in your package's
261+
#' `NAMESPACE` file, this implies having routine registration code of the form:
262+
#'
263+
#' ```
264+
#' // The definition for this function comes from the file 'src/test-runner.cpp',
265+
#' // which is generated via `testthat::use_catch()`.
266+
#' extern SEXP run_testthat_tests();
267+
#'
268+
#' static const R_CallMethodDef callMethods[] = {
269+
#' // other .Call method definitions,
270+
#' {"run_testthat_tests", (DL_FUNC) &run_testthat_tests, 0},
271+
#' {NULL, NULL, 0}
272+
#' };
273+
#'
274+
#' void R_init_<pkg>(DllInfo* dllInfo) {
275+
#' R_registerRoutines(dllInfo, NULL, callMethods, NULL, NULL);
276+
#' R_useDynamicSymbols(dllInfo, FALSE);
277+
#' }
278+
#' ```
279+
#'
280+
#' replacing `<pkg>` above with the name of your package, as appropriate.
281+
#'
260282
#' See [Controlling Visibility](https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Controlling-visibility)
261283
#' and [Registering Symbols](https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Registering-symbols)
262284
#' in the **Writing R Extensions** manual for more information.

man/use_catch.Rd

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)