Learn R Programming

rgl (version 1.3.1)

safe.dev.off: Close graphics device in a safe way.

Description

The dev.off function in grDevices doesn't restore the previous graphics device when called. This function does.

Usage

safe.dev.off(which = dev.cur(), prev = dev.prev())

Value

The number and name of the new active device. It will not necessarily be prev if that device isn't already open.

Arguments

which

Which device to close.

prev

Which device to set as current after closing.

Author

Duncan Murdoch

Details

This function closes device which if it is not device 1, then calls dev.set(prev) if there are any devices still open.

References

https://bugs.r-project.org/show_bug.cgi?id=18604

Examples

Run this code
# 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()

Run the code above in your browser using DataLab