[R] close specific graphics device

Dalthorp, Daniel ddalthorp at usgs.gov
Tue Dec 15 21:51:39 CET 2015

dev.off(which) can be used to close a specific graphics device where
"which" is the index of the device, but is there a way to assign a custom
number (or name) to a windows device so that specific window can be later
closed via dev.off (or some other method) if it is open?

The following does NOT work. The target device is not open when its dev.off
is called, and another window that later got assigned the original index
associated with the target device is closed instead.

plot(0,0,type='n') # target window to close
text(0,0,"close me")

# unbeknownst to the programmer, user closes device by clicking the red "X"

# user draws a new graph that he wants to keep open
text(1,1,"do not close me")

# now it's time for the program to close the original graphics device (if
it still happens to be open)

# the wrong device has been closed because the original window had closed
and the index associated with original graph is now associated with
something else


I'm looking for something like:

dev.off(which = "original figure") or dev.off(which = n), where n is a
custom index (like 10000) that will not be later assigned to a different
device [unless explicitly assigned that index].

Any help would be greatly appreciated.


Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalthorp at usgs.gov

	[[alternative HTML version deleted]]

More information about the R-help mailing list