[R] png inside loop

David Winsemius dwinsemius at comcast.net
Mon Mar 7 18:56:40 CET 2011


You need to print lattice objects. See the FAQ.

--  
David.
On Mar 7, 2011, at 12:28 PM, Sacha Viquerat wrote:

> hello list! I'm sorry, I just stumbled over this strange behaviour  
> (at least I am not able to explain the behaviour, therefore I assume  
> it to be a strange behaviour):
>
> attach(water) # I know, this is not recommended
>
> names(water[3:10])
> [1] "temp" "pH"   "DO"   "BOD"  "COD"  "no3"  "no2"  "po4"
>
> for (i in names(water)[3:10]){
>    fname<-paste("Henni/GFX/fem",i,".png",sep="")
>    mname<-paste("Henni/GFX/mal",i,".png",sep="")
>    png(fname,1000,1000)
>    xyplot(N_female~eval(parse(text=i)) |group,xlab=i,ylab="Abundance")
>    graphics.off()
>    png(mname,1000,1000)
>    xyplot(N_male~eval(parse(text=i)) |group,xlab=i,ylab="Abundance")
>    graphics.off()
> }
>
> well, to anyone's surprise, there are no plots in the folder. the  
> loop finishes (i, fname and mname have values assigned) and executing
>
> png(fname,1000,1000)
> xyplot(N_female~eval(parse(text=i)) |group,xlab=i,ylab="Abundance")
> graphics.off()
>
> does produce a png in the folder. I assume this to be caused by the  
> png function, since removing the graphics.off() and playing with  
> dev.off() and the likes did not help. anyone ideas?? am I missing  
> the obvious??
>
> ______________________________________________
> R-help at r-project.org 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list