开发者

Disable GUI, graphics devices in R

开发者 https://www.devze.com 2023-01-08 18:56 出处:网络
Is there an easy way to turn of all GUI elements in R and run it solely from the command line on OSX?

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 sav开发者_开发问答e 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.


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)


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


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.


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")
0

精彩评论

暂无评论...
验证码 换一张
取 消