Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable GUI, graphics devices in R

Tags:

r

Is there an easy way to turn of all GUI elements in R and run it solely from the command line on OSX?

I'm trying to replicate the behavior of a remote linux terminal on my OSX machine. Thus plot() should just save a file and things like CRAN mirror selection should be text, not a Tk interface. I'm having trouble finding where to set this behavior.

like image 781
Tristan Avatar asked Jul 26 '10 23:07

Tristan


People also ask

What is a graphical device in R?

A graphics device is something where you can make a plot appear. Examples include. A window on your computer (screen device) A PDF file (file device) A PNG or JPEG file (file device)

Which of the following are device function in R?

The R. devices package provides functions for creating plots and image files in a unified way regardless of output format (EPS, PDF, PNG, SVG, TIFF, WMF, etc.). Default device options as well as scales and aspect ratios are controlled in a uniform way across all device types.


3 Answers

I had this exact question and wanted a way to do it without changing my existing code. I usually run with graphics support but sometimes I'll run a script on the server for a larger dataset and then I just want the plots to be output somewhere automatically.

In Dirk's answer Ian Fellows gives the simple solution. On the command line in R type:

options(device=pdf)

And then any plots will be written to the current directly to an Rplots.pdf file.

If you want the files to not be plotted at all then use

options(device=NULL)
like image 112
rateldajer Avatar answered Oct 07 '22 03:10

rateldajer


For the plots you can just direct the output to a file using the pdf() command (or png(), jpeg()...).

like image 27
Matti Pastell Avatar answered Oct 07 '22 02:10

Matti Pastell


I don't own an OS X box, but did you try to unset the X11 environment variable DISPLAY:

DISPLAY="" R --vanilla

When I do that on Linux and query R for capabilties(), x11 comes up as FALSE as desired.

like image 34
Dirk Eddelbuettel Avatar answered Oct 07 '22 02:10

Dirk Eddelbuettel