[R] savePlot(type="wmf") in loop fails, since too fast

Dieter Menne dieter.menne at menne-biomed.de
Fri Sep 16 15:51:58 CEST 2005


Christoph Lehmann <christoph.lehmann <at> gmx.ch> writes:

> working with R-2.1.1 on winxp, in a loop I draw to a trellis.device which
> takes some time. After the drawing I call savePlot().
> it seems, the loop is too fast for the savePlot() call to finish. 

I virtually see the computer being overrun by her/his/its own plotting 
function, all semaphores blinking like mad...

When in a loop, you must use print() to output the plot. Easy to forget, I 
remember that even Douglas Bates once was close to calling Deepayan who was far 
away in India one hour before the presentation.

library(lattice)
for (i in 1:10) {
  x = rnorm(10)
  y = rnorm(10)
  p = xyplot(x~y,main=paste("Plot",i))
  print(p)
  savePlot(paste("Plot",i, sep=""))
}

But as far I know, savePlot anyway is not the preferred methode to print 
trellis, is just just happens to work somehow. Here is my preferred method: 
print everything to a postscript file (nice one-file solution), and extract to 
emf-file with pstoedit/Ghostgum when you really need it.

trellis.device("postscript",file="Myplots.ps",color = T)
for (i in 1:10) {
  x = rnorm(10)
  y = rnorm(10)
  p = xyplot(x~y,main=paste("Plot",i))
  print(p)
}
dev.off()

Dieter




More information about the R-help mailing list