10

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.

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
Tristan
  • 6,776
  • 5
  • 40
  • 63

4 Answers4

4

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)
rateldajer
  • 138
  • 7
3

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

Matti Pastell
  • 9,135
  • 3
  • 37
  • 44
2

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.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • That does indeed disable x11, but leaves acqua and tcltk true. plot() still opens a quartz window. – Tristan Jul 26 '10 at 23:17
0

I don't run OSX but you could attempt to run R from the Terminal application, rather than the Mac OSX launcher, and see whether that runs as you need.

As Matti writes, you can send output to files using the following commands; but I don't know if that's really the substance of your question.

png("pngfile.png")
plot(foo)
title(main="bar")
dev.off()

So instead of the quartz graphical object, your output goes to the file.

Similarly, you can output what would normally appear in the terminal to a file.

sink("foo.file")
Ben M
  • 171
  • 5
  • Even the command line R opens a quartz window by default if the capability exists. The only way I've found to disable it is to compile R without aqua support but that's less than ideal. – Tristan Jul 28 '10 at 16:05
  • 1
    Using the `png()' command is a really bad example, because png actually requires an X11-connection to do rendering. Replace it by something like `pdf()' – parasietje Apr 22 '14 at 14:01
  • Latest R can be compiled to have png() support without requiring X11 (by using canvas). Just in case anyone reads this comment. – dieresys Oct 28 '16 at 17:57