[R-pkg-devel] Error in CHECK caused by dev.off()

Helmut Schütz he|mut@@chuetz @end|ng |rom beb@c@@t
Thu Jul 23 22:44:41 CEST 2020

Hi Sebastian,

Sebastian Meyer wrote on 2020-07-23 16:52:
> Back to the original topic:


> Calling graphics.off() in example code will also disturb standard R CMD
> check. Before running the examples, R CMD check opens a pdf device to
> store any graphics output [1]. You will find the resulting pdf file in
> {PACKAGE}.Rcheck/{PACKAGE}-Ex.pdf after R CMD check.

Ah! For years I was wondering where the PDF comes from.

> R CMD check will eventually fail from trying to close this pdf device
> after running the examples [2], if you have already closed all graphics
> devices (including this pdf device) through code in your examples. This
> is where the
> Error in grDevices::dev.off() :
>    cannot shut down device 1 (the null device)
> Execution halted
> actually came from.

OK, now I have:
if (file.exists("myfile") & !is.null(dev.list()["png"]) {
You made my day. No error in check() any more.

> Finally, […] the png device may not even be available.


> So it is reasonable to condition on
> capabilities("png")


>   or to put such examples in \donttest.

It was already in \donttest{} but check() ignored that.

> HTH!

It did. Additionally I've learned a new abbreviation...


Ing. Helmut Schütz
BEBAC – Consultancy Services for
Bioequivalence and Bioavailability Studies
Neubaugasse 36/11
1070 Vienna, Austria
E helmut.schuetz using bebac.at
W https://bebac.at/
F https://forum.bebac.at/

More information about the R-package-devel mailing list