[R] how to plot and save plots in batch mode

Kinoko andzsinszan at gmail.com
Tue Nov 25 11:11:44 CET 2008


Dear list,

This is not a question but a rather short note how to save a plot
if it was created in batch mode.
It took me like 2 hours to figure it out, I hope it can save time
for those who - like me - are not really fast in picking up
diosyncrasies of R. (as far as I remember I had no problems whatsoever
batch plotting in
gnuplot, matplotlib, matlab... )

The problem I had was that while  I could plot and save my data using
RGui,
the same script did not work in batch mode.

plot(x,y, bla-bla... )
...
dev.set (2)
dev.print (device=png, file=outFile, bla-bla)

But this does not work in BATCH mode.
The error msg is:
"... can only print from a screen device"
Sure, the plotting window does not pop up in batch mode.

What I had to do was to to put a command:

windows()

before starting the plot. Now I can save my plots in batch mode

Well, I am more than sure, that there are more elegant solutions
without invoking the window...



More information about the R-help mailing list