File: safe.dev.off.Rd

package info (click to toggle)
rgl 1.3.34-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,968 kB
  • sloc: cpp: 23,234; ansic: 7,462; javascript: 6,125; sh: 3,555; makefile: 2
file content (60 lines) | stat: -rw-r--r-- 1,200 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
\name{safe.dev.off}
\alias{safe.dev.off}
\title{
Close graphics device in a safe way.
}
\description{
The \code{\link{dev.off}} function in \pkg{grDevices} doesn't restore
the previous graphics device when called.  This function does.
}
\usage{
safe.dev.off(which = dev.cur(), prev = dev.prev())
}
\arguments{
  \item{which}{
Which device to close.
}
  \item{prev}{
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.  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}
}
\author{
Duncan Murdoch
}
\examples{
# Open a graphics device
dev.new()
first <- dev.cur()

# Open a second graphics device
dev.new()
second <- dev.cur()
second

# Open another one, and close it using dev.off()
dev.new()
dev.off()
dev.cur() == second # Not the same as second!

# Try again with safe.dev.off()
dev.set(second)
dev.new()
safe.dev.off()
dev.cur() == second

# Close the other two devs
safe.dev.off()
safe.dev.off()
}