Closed wch closed 3 years ago
I'm fairly sure this is only ever a problem if that code is run at the console when a graphics device isn't already open, and since this code is wrapped in attempt_with_device(dev_fun, code)
, that should never happen...
thematic:::attempt_with_device(
grDevices::png,
tryCatch({
plot(1, family = "Righteous")
},
warning = function(e) {
message("Caught a warning")
}
)
)
#> Caught a warning
This is the code that checks whether a font is available: https://github.com/rstudio/thematic/blob/21256e257aff9d435dd1ad3606bea75a81c22574/R/hooks.R#L161-L180
However, it may not give an accurate answer, because R can render graphics asynchronously. For example, in a new R session in the terminal, run this code two times:
This is the result:
The first time, the warnings are not caught, but the second time, they are caught. (The logic here is roughly the same as the logic used in thematic.)
For testing, here's an example using grid which does the same thing: