I'd like to use an R CMD BATCH script as part of a chron job that is set up to run every hour. The trouble is that the script creates a graphical output in a file via png(), and apparently this in turn works through X. When cron invokes the job, no X server is available -- I suppose that the DISPLAY variable is not set -- and so R exits with an error message in the output file. (If I run the same script in an environment where an X server is properly available, it works as I want it to.) I tried setting DISPLAY to thecomputername:0.0 (where "thecomputername" is the X.Y.Z form of the computer's name as names it for ssh etc.), but that didn't work. Any advice about how to persuade the graphics subsystem to bypass X, or how to set DISPLAY in a safe way to run in a cron job? This is a linux system (a recent RedHat server system) with R 2.2.1. Thanks, Mark Liberman
Try using png2() in R.utils, which immitates png() but uses bitmap() and ghostscript to create the PNG file. You need to set 'R_GSCMD' to tell R where ghostscript is located - you can use System$findGhostscript() at startup to let R try to locate ghostscript for you. /H On 4/19/07, Mark Liberman <myl at cis.upenn.edu> wrote:> I'd like to use an R CMD BATCH script as part of a chron job that is set > up to run every hour. > > The trouble is that the script creates a graphical output in a file via > png(), and apparently this in turn works through X. > > When cron invokes the job, no X server is available -- I suppose that > the DISPLAY variable is not set -- and so R exits with an error message > in the output file. (If I run the same script in an environment where an > X server is properly available, it works as I want it to.) > > I tried setting DISPLAY to thecomputername:0.0 (where "thecomputername" > is the X.Y.Z form of the computer's name as names it for ssh etc.), but > that didn't work. > > Any advice about how to persuade the graphics subsystem to bypass X, or > how to set DISPLAY in a safe way to run in a cron job? > > This is a linux system (a recent RedHat server system) with R 2.2.1. > > Thanks, > > Mark Liberman > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
This is in the FAQ, if I remember correctly... However, alternatively: As Jeff Horner recently pointed out on the list, the Cairo package is a good way of generating png without needing an X display. You may want to look into that. I've just installed cairo on our CentOS boxes and the Cairo package from CRAN. Andy From: Mark Liberman> > I'd like to use an R CMD BATCH script as part of a chron job > that is set up to run every hour. > > The trouble is that the script creates a graphical output in > a file via png(), and apparently this in turn works through X. > > When cron invokes the job, no X server is available -- I > suppose that the DISPLAY variable is not set -- and so R > exits with an error message in the output file. (If I run the > same script in an environment where an X server is properly > available, it works as I want it to.) > > I tried setting DISPLAY to thecomputername:0.0 (where > "thecomputername" > is the X.Y.Z form of the computer's name as names it for ssh > etc.), but that didn't work. > > Any advice about how to persuade the graphics subsystem to > bypass X, or how to set DISPLAY in a safe way to run in a cron job? > > This is a linux system (a recent RedHat server system) with R 2.2.1. > > Thanks, > > Mark Liberman > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > >------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments,...{{dropped}}