Disable Gui, Graphics Devices in R

Disable plot display in R

You can wrap the call in

pdf(file = NULL)

and

dev.off()

This sends all the output to a null file which effectively hides it.

Disable/suppress tcltk popup for CRAN mirror selection in R

Dirk provides ways to avoid the menus altogether, but to answer your question as posed, I think you want

options(menu.graphics=FALSE)

I tracked this option down by finding the class of objects returned from help (it's help_files_with_topic), scanning utils:::print.help_files_with_topic and finding the line

menu(txt, title = gettext("Choose one"), graphics = getOption("menu.graphics"))

make sure graphics device gets closed

on.exit() is made for situations just like this. It's good practice to use it whenever opening a (file or other) connection in a non-interactive setting.

f <- function() {
pdf(tempfile()) # tempfile() so example doesn't clutter up working directory.
on.exit(dev.off())
plot(randomNonExistentObjectName)
}

f()
# Error in plot(randomNonExistentObjectName) :
# object 'randomNonExistentObjectName' not found

dev.list()
# NULL

R dev.copy() with non-GUI devices for batch graphic scripts

You need to call dev.control('enable'). From ?dev.copy:

dev.copy copies the graphics contents of the current device to the
device specified...(If recording is off on the current device, there
are no contents to copy: this will result in no plot or an empty
plot.) ... The displaylist can be turned on and off using dev.control.
Initially recording is on for screen devices, and off for print
devices.

How to plot in RStudio and not have a new window pop up (R Graphics: Device (ACTIVE)?

For others who like me may still encounter this issue:

This is probably caused by an R update to 3.3.2 and is fixed by installing a newer version of RStudio. In my case 1.0.136 did the trick.

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

See ?par. The idea is that you save them as they are when you found them, and then restore:

old.par <- par(mar = c(0, 0, 0, 0))
## do plotting stuff with new settings

Now restore as they were before we changed mar:

par(old.par)


Related Topics



Leave a reply



Submit