Nothing
knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
print_code <- function(filename) { cat(readChar(filename, file.info(filename)$size)) }
This vignette builds and tests some example projects which use mockcpp, to show you how you can include them in your package.
We have created a toy random number generator using Rcpp
print_code( system.file('testrcpp/src/code.h', package = 'mockcpp', mustWork = TRUE) )
Let's say we want to mock the output of our RNG. We can write a testthat test like so:
print_code( system.file('testrcpp/src/test-example.cpp', package = 'mockcpp', mustWork = TRUE) )
We can then build our package and run the test to ensure our mocking works:
# load test package pkgload::load_all( system.file('testrcpp', package = 'mockcpp', mustWork = TRUE) ) # run the test testthat::test_file( system.file( 'testrcpp/tests/testthat/test-cpp.R', package = 'mockcpp', mustWork = TRUE ) )
We can create a similar test for code written using cpp11.
Here's a toy RNG:
print_code( system.file('testcpp11/src/code.h', package = 'mockcpp', mustWork = TRUE) )
And the corresponding test:
print_code( system.file('testcpp11/src/test-example.cpp', package = 'mockcpp', mustWork = TRUE) )
We can build and test this package in a similar way:
# load test package pkgload::load_all( system.file('testcpp11', package = 'mockcpp', mustWork = TRUE) ) # run the test testthat::test_file( system.file( 'testcpp11/tests/testthat/test-cpp.R', package = 'mockcpp', mustWork = TRUE ) )
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.