This pair of functions makes it easy to create paired R and test files, using the convention that the tests for R/foofy.R should live in tests/testhat/test-foofy.R. You can use them to create new files from scratch by supplying name, or if you use RStudio, you can call to create (or navigate to) the paired file based on the currently open script.

use_r(name = NULL, open = NULL)

use_test(name = NULL, open = NULL)



Either a name without extension, or NULL to create the paired file based on currently open file in the script editor. If the R file is open, use_test() will create/open the corresponding test file; if the test file is open, use_r() will create/open the corresponding R file.


If, NULL, the default, will open the file when in an interactive environment that is not running tests. Use TRUE or FALSE to override the default.

See also

The testing and R code chapters of R Packages.