Today I am having a problem with RStudio and unit testing.
My team wants to have unit tests for all our code to ensure there are no bugs. Recently we discovered there are 8 mysterious warnings in our unit tests which do not produce error messages in the RConsole.
We cannot find where the warnings are coming from. What is the best way to show warnings that are hidden from testthat output when you do not know the location of the warning? We want get warnings to show up in the RConsole automatically after clicking the "Run Tests" button in RStudio. How can we display more than one warning at a time?
Here is what my team tried so far:
We added the following code to expect silent output, but mysterious warnings still exist.
test_that("initialize without warnings", {
expect_silent({
# our code
})
})
We converted all warnings to fatal errors using R options, but we can only display the first warning.
options(
warn = 2,
error=recover
)
We looked in the RConsole for warning messages, but there is zero output for warnings. There is only a number indicating that there are 8 warnings.
After trying all three steps separately, we cannot figure out how to see warning messages created during a unit test. How can we see all the warning messages at the same time?
My first instinct when seeing the object 'testthat_print' not found error was that you might be working with an older version of testthat. After a little search I found this topic that indeed seems to link mysterious warnings to old versions: