[R] close specific graphics device
drjimlemon at gmail.com
Tue Dec 15 23:38:58 CET 2015
The range of device numbers seems to be 1-63. There doesn't appear to be a
means of explicitly setting the device number when calling dev.new, and
devices are numbered sequentially when they are opened. This means that
even if you did know that the device number was, say, 4 it would be
possible to close that device and open another device with the number 4.
I suppose it would be possible to write wrapper functions for this, but I
have to leave at the moment, so perhaps tomorrow.
On Wed, Dec 16, 2015 at 7:51 AM, Dalthorp, Daniel <ddalthorp at usgs.gov>
> 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]]
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help