[r] Reset the graphical parameters back to default values without use of dev.off()

Such as margins, orientations and such...

dev.off() does not work for me. I am often using RStudio, with its inbuilt graphics device. I then have plotting functions, which I want to plot either in the default RStudio graphics device, or if I called X11(), before in a new window.

This behaviour doesn't work with dev.off(). If my plotting function always calls dev.off(), it might inadvertently close the X11() window and instead plot in the RStudio device. If I always call dev.off() followed by X11(), it would always plot in a new window, even if I wanted to plot in the RStudio device.

Ordinarily that could be solved with getOption("device"), however, that always returns RStudioGD.

This question is related to r rstudio

The answer is