, ,

When running tests for a package, it’s important that the console output is unadulterated since test results are printed with formatting. My code is littered with log output using my futile.logger package [1]. Since arbitrary appenders are supported in futile.logger, a neat trick is to redirect output to a file when running the tests. This is as simple as adding the following lines to the top of a testthat or RUnit script:


Now when R CMD check runs, the console output will be clean and all the log output from your package will be directed to <package>.Rcheck/<package>/tests/unit_tests.log.

Similarly, if you want to modify the log threshold when running tests, throw in a change of threshold.


So you get all of this without needing to change any of the code in the package proper.


[1] The futile.logger package is available on CRAN, while the latest version is on github. To install from github, run the following from your R shell.

install_github('lambda.r', 'zatonovo')
install_github('futile.logger', 'zatonovo')