I have a weird example which fails and I don't understand why. If I
put dev.off() inside my function, it produces a bad image file. But
if I run what I think should be equivalent code with dev.off() running
outside my function, it works. Why does the location of dev.off
matter?
library(Cairo)
library(ggplot2)
foo<-function(){
Cairo(file="a.png")
cat(dev.cur(), "\n")
qplot(1:10,1:10)
dev.off();
}
foo()
# file a.png is bad
foo1<-function(){
Cairo(file="a.png")
cat(dev.cur(), "\n")
qplot(1:10,1:10)
}
foo1(); dev.off()
# file a.png is good
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.