[R] dev2bitmap from a script invoked by another process

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Fri Apr 28 17:42:24 CEST 2000

"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, ...)


   dev.off() #close (and flush!) PS device
   system(paste("mv Rplots.ps", tmp))


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

More information about the R-help mailing list