Skip to content

Commit

Permalink
Handle edge cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmurdoch committed Oct 3, 2023
1 parent 1e3b630 commit 611f589
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 6 additions & 2 deletions R/bgplot3d.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
safe.dev.off <- function(which = dev.cur(), prev = dev.prev()) {
force(prev)
grDevices::dev.off(which)
if (which != 1) {
force(prev)
grDevices::dev.off(which)
}
if (length(dev.list()))
dev.set(prev)
else
c("null device" = 1)
}

dev.off <- function(...) stop("Use safe.dev.off() instead!")
Expand Down
8 changes: 7 additions & 1 deletion man/safe.dev.off.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ Which device to close.
Which device to set as current after closing.
}
}
\details{
This function closes device \code{which} if it is not device 1,
then calls \code{\link{dev.set(prev)}} if there are any devices still
open.
}
\value{
The number and name of the new active device.
The number and name of the new active device. It will not
necessarily be \code{prev} if that device isn't already open.
}
\references{
\url{https://bugs.r-project.org/show_bug.cgi?id=18604}
Expand Down

0 comments on commit 611f589

Please sign in to comment.