Carel, Roland
2000-Apr-28 14:48 UTC
[R] dev2bitmap from a script invoked by another process
Issue: I have a R script that is invoked periodically by another process. In the script, a graphics is generated and I want to get a the image for the graph as a jpeg. Here is a prototypical version of the script (try.R): plot(1) dev2bitmap("try.jpg", type = "jpeg") I am running R-1.0.0 on Solaris 7. The script is invoked as: R --vanilla < try.R A file named try.jpg is created but it contains a blank image, not the plot created from the script. Device inserted after plot(1) tells me that the current device is postscript. If I specify: postscript(file = "try.ps"), a file try.ps is created that contains a postscript rendition of the plot. The try.jpg is also created but is as previously described. If I run the script in interactive mode, the file try.jpg is created and contains the plot, as expected. I know I can create the postscript file and then use ghostscript to convert it but I was wondering if it is possible to create the jpeg directly from R. Thanks for any help you might have. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard BSA
2000-Apr-28 15:42 UTC
[R] dev2bitmap from a script invoked by another process
"Carel, Roland" <rcarel at netgenics.com> writes:> plot(1) > dev2bitmap("try.jpg", type = "jpeg")...> The script is invoked as: R --vanilla < try.R > A file named try.jpg is created but it contains a blank image, not the plot > created from the script....> I know I can create the postscript file and then use ghostscript to convert > it but I was wondering if it is possible to create the jpeg directly from R.Gah. This is silly. The problem is that dev2bitmap calls dev.print to print the current device as postscript. When run noninteractively, the current device *is* postscript, but that is not a replayable driver. A quick solution is to explicitly start X11() at the start of your script (which has a number of drawbacks, but might be good enough). A better fix would be to doctor dev2bitmap by replacing dev.print(device=postscript, file=tmp, width=width, height=height, pointsize=pointsize, paper="special", horizontal=FALSE, ...) with dev.off() #close (and flush!) PS device system(paste("mv Rplots.ps", tmp)) (Untested!) Or something pretty similar. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._