Skip to content
Back to formatted view

Raw Message

Message-ID: <51f5cc83-4ccb-17cd-18cc-727792c35998@bebac.at>
Date: 2020-07-23T20:44:41Z
From: Helmut Schütz
Subject: [R-pkg-devel] Error in CHECK caused by dev.off()
In-Reply-To: <e85d52e6-fced-a0d7-b87d-7ea60006d618@fau.de>

Hi Sebastian,

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

THX!

> 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"]) {
 ? invisible(dev.off(dev.list()["png"]))
}
You made my day. No error in check() any more.

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

Ouch!

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

Done.

>   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...

Helmut

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