0

I'm often playing around with par() png() and so on, and then I often need to manually execute a random line with dev.off() in order to reset all my graphical parameters.

Looking at the doc I can't find a shortcut that would allow me to do it quickly. Did I miss something? if not, is it possible to create something similar (ie a shortcut that would send dev.off() to R)?

Simon C.
  • 1,058
  • 15
  • 33

1 Answers1

2

From ?par:

‘par()’ (no arguments) or ‘par(no.readonly = TRUE)’ is used to get all the graphical parameters (as a named list). Their names are currently taken from the unexported variable ‘graphics:::.Pars’.

So you can do something like:

#get the default values
x<-par(no.readonly=TRUE)
#set some values
par(mfrow=c(2,1))
#plot something
plot(1:10)
plot(10:1)
#reset the pars
do.call(par,x)
#new plot
plot(1:10)
nicola
  • 24,005
  • 3
  • 35
  • 56
  • thanks! That I supposed I should put it ad the end of my function in order to reset par with its orginial value right? my question now is more about how integrate this (so your `do.call(par,x)`) with the vim-R plugin in order that I only need to press some shortcut (`\off` or whatever) to run it whenever I want? – Simon C. Sep 27 '16 at 09:04
  • 1
    Yes, you are correct. If your plot is in a function, consider also using `on.exit()`, which allows you to execute some commands just before exiting from a function (whether successfully or not). – nicola Sep 27 '16 at 09:11