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
Tiff Plot Generation and Compression: R VS. Gimp VS. Irfanview VS. Photoshop File Sizes
Change Thickness of a Marker in Ggplot2
Passing Ellipsis Arguments to Map Function Purrr Package, R
Filter Dataframe Using Global Variable with The Same Name as Column Name
Customise The Infowindow/Tooltip in R -> Plotly
Removing "Nul" Characters (Within R)
Quantiles by Factor Levels in R
How to Use Stat_Function by Group
Select List Element Programmatically Using Name Stored as String
Splitting (1:N)[Boolean] into Contiguous Sequences
Add Points to Usmap with Ggplot in R
R Bookdown - Custom Title Page
Error: C Stack Usage Is Too Close to The Limit in R
Why Does Apt-Get Install R-Base Install 3.2.3 Instead of 3.4.0 in R
Error: $ Operator Not Defined for This S4 Class
Download Multiple CSV Files with One Button (Downloadhandler) with R Shiny