Open nanxstats opened 1 month ago
The culprit is in these two places where graphics::par()
and graphics::strwidth()
were called:
https://github.com/Merck/r2rtf/blob/307c112e83c84a8521229f75dd145dfc57493c3c/R/rtf_strwidth.R#L56
By replacing them both with a constant number, the problem goes away. Looks like by calling these functions in graphics, a PDF device is somehow triggered when running the tests in RStudio interactively.
This unit test using graphics::strwidth()
also needs side effect isolation, otherwise, Rplots.pdf
will be generated:
It seems it only happens while running unit test. I did not see the RPlots.pdf
is created by running the code above in an interactive R sessions.
Guess a graphic device is initiated when devtools::test()
detected graphics
package is used. As I do see a RPlots.pdf
file is created if we call pdf()
.
I am OK to live with it.
I should have been clearer - this only happens when you click the "Run Tests" button above the code editor or the "Test" button in the Build panel in RStudio, but not when you send the code into the R console.
Regardless, I'd say it will be productive to get this fixed, because every package that have tests with underlying code using r2rtf will get this unavoidable side effect - and it can be confusing and annoying. For example, see previous discussions:
https://github.com/Merck/metalite.ae/pull/75 https://github.com/Merck/metalite.ae/pull/73
To reproduce the issue:
Run
usethis::use_r("myfun")
and put this function into it:Run
usethis::use_test("myfun")
to create this test:Run
devtools::document()
anddevtools::load_all()
.Clicking the "Run Tests" button or the "Test" button in the Build panel in RStudio will generate a blank, redundant
tests/testthat/Rplots.pdf
, while no suchRplots.pdf
is generated when runningdevtools::test()
ordevtools::test_active_file()
in the R console.Reproduced under macOS, Windows, and Posit Cloud.