Quick tip on controlling log output in tests

November 11, 2013

(This article was first published on Cartesian Faith » R, and kindly contributed to R-bloggers)

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 .Rcheck//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')


To leave a comment for the author, please follow the link and comment on their blog: Cartesian Faith » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)