What is a null graphics device?

2019-02-13 00:17发布

问题:

I'm reading the R help page for ?devAskNewPage (it was linked from ?par...ask). I can't understand what par(ask=F) / par(ask=T) does.

What do I need to read about to understand this:

 If the current device is the null device, this will open a
 graphics device.

 ...

 The precise circumstances when the user will be asked to confirm a
 new page depend on the graphics subsystem.  Obviously this needs
 to be an interactive session.  In addition ‘recording’ needs to be
 in operation, so only when the display list is enabled (see
 ‘dev.control’) which it usually is only on a screen device.

What are devices, what is the null device, and what is a graphics subsystem? What is 'recording'? Are we talking about the difference between writing to png file and writing to the screen?

This feels a bit like learning what standard output and standard input are. Everybody uses the words but it was hard to find the definition (it was also hard to understand it). I googled for "null graphics device" and the top results don't explain to me, as a novice, what I need to know, in order to know where to look.

Just some links to the proper introductory reading would suffice. Thank you.

回答1:

In R, a device is the mechanism to produce graphical plots. This can be to screen (e.g. windows ) or to a variety of file types (e.g. png, pdf, tiff, etc).

For an entry point to the help file on devices, see ?Devices. The default devices for the three main operating systems are:

  • MS Windows: windows
  • Unix: X11
  • OS X: quartz

The null device means that no device is active. Here is a short code sequence that I used to find out whether I had an open device (dev.cur) and close it (dev.off). When I closed it, the remaining device was the null device.

> dev.cur()
windows 
      2 

> dev.off(2)
null device 
          1 

> dev.cur()
null device 
          1 

The meaning of graphics sybsystem is a bit more unclear. This seems to be the only page in all of help that uses the term. Thus I am guessing that the following are graphics subsystems:

  • base graphics
  • grid graphics (and anything built on top, including lattice and ggplot2)
  • rgl in package rgl