R: preventing par() from opening a new window when

2019-07-04 11:23发布

问题:

The question says it all.
Sometimes you need to make preliminary calculations to format your plot and you don't want a window to show and most of all stealing the focus.

For example, say that you want to know the height of the lines used as margins, you might want to use:

par("mai")/par("mar")

I use to query often the graphical parameters to define what will be the figure output and find the popping window distracting and time consuming.

One possibility is to send everything to a bogus device with a custom quiet par():

qpar=function(...){
    pdf()
    ret=par(...)
    dev.off()
    unlink('Rplots.pdf')
    ret
}

and so without any noise:

par("mai")/qpar("mar") 
# [1] 0.2 0.2 0.2 0.2

It seems a bit overkill and does not work for the X11 device (or windows()).

Also pdf.options(), windows.options() etc. are limited to a few device specific parameters.

标签: r graphics plot