Search code examples
runit-testingpackage

How to run R package tests without building or installing the package?


R CMD check automatically runs tests located in tests/ directory. However running the tests this way requires building the package first. After that R CMD check goes through various different sanity checks before finally reaching the tests at the end.

Question: Is there a way to run those tests without having to build or install the package first?

NOTE: without using testthat or other non-standard packages.


Solution

  • To summarise our discussion.

    1. To my knowledge there is no standard alternative to R CMD check for unit testing provided by base R
    2. Typically for unit testing, I source everything under R/ (and dyn.load everything under source/) and then source everything under tests/ (actually, I also use the Example sections of the help pages in the man/ directory as test cases and compare their outcome to those from previous package versions)

    I assume that these are the basic testing functionalities provided by devtools and testthat. If you expect to develop multiple packages and want to stay independent from non-base-R, I'd recommed to automate the above processes with custom scripts/packages.

    I'd recomment looking into http://r-pkgs.had.co.nz/tests.html.