Reputation: 6651
I have an R script that runs just fine from inside R or from the command line. Its operation is pretty straightforward. It just takes some regularly updated data, does some analysis, makes some plots, and saves them to disk. I want to run it automatically somewhat in sync with the data updates, so I am trying to run it under a cron job. It does everything just fine until it gets to writing the images to disk. Then it tells me it can't open the first image, and fails. I have tried all the stuff I can think of: checking permissions in the run directory, making sure cron is running as me, switching my cron command from "R CMD BATCH" to "Rscript". Nothing has worked. Again, the script runs just fine from inside R or from the command line. Anyone have any ideas about what else I can do? (BTW, I did find a similar question to this on this site, but the answers given there didn't help in my particular case.)
The offending code seems to be:
png(file=nd_pic_image_names[1],height=720,width=720)
The error returned is:
Error in X11(paste("png::", filename, sep = ""), g$width, g$height, pointsize, :
unable to start device PNG
Calls: png
In addition: Warning message:
In png(file = nd_pic_image_names[n], height = 720, width = 720) :
unable to open connection to X11 display ''
Execution halted
I don't understand the "X11" stuff. I don't have a reference to X11() anywhere in the code and I am not trying to plot prior to opening (or trying to open) my PNG file. Thanks.
Upvotes: 1
Views: 877
Reputation: 368201
Start simple:
Add a cronjob that simply executes a single command, maybe format(Sys.time())
, via an Rscript file -- mostly to demonstrate (to yourself) that you can run an R script
Convert your existing code into an R script you can run at the command-line. Make sure you have no dependencies on environment variables etc pp
Add your script as a cronjob. If it fails, do it piecemeal by adding to the script created in 1.
Upvotes: 1