[R] jpeg() creating empty files with qplot() in a loop
B. Bogart
bbogart at sfu.ca
Thu Feb 21 19:51:33 CET 2008
Hello all,
I'm stuck with a strange issue with writing jpegs of plots to a folder
in a loop.
This works:
for (step in 1:length(steps)) {
jpeg(filename=paste("frame_",sprintf("%05d",step),".jpg",sep=""))
plot(steps[[step]])
dev.off()
}
But if I use qplot to generate the plot (which is my aim):
for (step in 1:length(steps)) {
jpeg(filename=paste("frame_",sprintf("%05d",step),".jpg",sep=""))
qplot(x, y, data=steps[[step]], geom="tile", fill=rgb(V1,V2,V3)) +
scale_fill_identity() + opts(aspect.ratio = .75)
dev.off()
}
I end up with a directory of empty files named correctly.
The following does work:
step <- 10
jpeg(filename=paste("frame_",sprintf("%05d",step),".jpg",sep=""))
qplot(x, y, data=steps[[step]], geom="tile", fill=rgb(V1,V2,V3)) +
scale_fill_identity() + opts(aspect.ratio = .75)
dev.off()
So what could be the difference between the last example and it running
in a loop, that the former generates a proper jpeg file and the lattter
does not?
Does something more special than dev.off() need to be done with qplot
output when in a loop?
Thanks,
B. Bogart
More information about the R-help
mailing list