4.7 Test driving a package
4.7.1 Using load_all()
Running load_all()
is the fastest way to re-load the functions in your package – much faster than installing it (install.packages(pkgName)
) and loading it into memory library(pkgName)
. This is helpful for iteratively updating or tweaking functions you’re working on.
4.7.2 Using test()
Running test()
runs load_all()
and then the test files that live in tests/testthat/
. If you have a test file which captures the behaviour in the function that you desire, you can quickly assess whether the changes you make in the function have worked by running test()
.
4.7.3 Coping with being impatient
check()
can take a long time and leave your console occupied. A solution to this is to run using the build tab (ctrl-shift-E) or as a separate job:
job::job({check()})
To test examples in your documentation without running check()
:
run_examples()
4.7.4 (Previous speaker’s) bad habit
I like to have a working_space.Rmd
in the package directory which I use to test package code away from the console. You’ll get a NOTE on the check:
N checking top-level files …
Non-standard file/directory found at top level:
'working_space.Rmd'
But you could also add this to .Rbuildignore
/.gitignore
.
It can be tricky to incorporate everything into a test script, and sometimes you may want to have a closer look at what’s going on within a function. This can more easily be done by throwing some earlier return()
s into your package functions, run load_all()
to make them effective and then running code in your working_space.Rmd
file.