I am encountering problems using the png() function to save around 20 charts to separate files. My script is conceptually structured as follows: ### <script> png("Image %03d.png") # the following are calls to user-defined functions I wrote that call plot, barchart, etc. with special arguments. myPlot("a") myPlot("b") myPlot("c") myBarchart("a") myBarchart("b") myBarchart("c") myBarchart2("a") myBarchart2("b") myBarchart2("c") dev.off() ### </script> When I run the code a few lines at a time it generates the images correctly. However, when I execute all lines of the script at once (Ctrl+A, Ctrl+R in the Rgui editor), the output doesn't get generated right. Most notably: - Only one plot created by myBarchart (or myBarchart2) gets saved, instead of all 3 - Some images are blank I'm having trouble isolating the problem to one line of code. I suspect there is some fundamental paradigm I'm not aware of about how R devices and images work, perhaps relating to the importance of the order in which the calls to png, dev.off(), etc. are executed, the required state of my workspace before I run the code (e.g. whether the previous plot window should be open or closed), or maybe even time dependency (do I need to insert timed pauses so that my diagram has time to render before saving to a file?). Does this ring a bell to anyone? I read the R documentation on devices and png(), and searched the mailing list archives and the web, but haven't figured out how to get this working. Any help would be appreciated. Thanks, Rex [[alternative HTML version deleted]]
On Thu, Jan 14, 2010 at 2:15 PM, Rex C. Eastbourne <rex.eastbourne@gmail.com> wrote:> I am encountering problems using the png() function to save around 20 > charts to separate files. > > My script is conceptually structured as follows: > > ### <script> > png("Image %03d.png") > > # the following are calls to user-defined functions I wrote that call plot, > barchart, etc. with special arguments. > myPlot("a") > myPlot("b") > myPlot("c") > > myBarchart("a") > myBarchart("b") > myBarchart("c") > > myBarchart2("a") > myBarchart2("b") > myBarchart2("c") > > dev.off() > ### </script> > > When I run the code a few lines at a time it generates the images > correctly. However, when I execute all lines of the script at once (Ctrl+A, > Ctrl+R in the Rgui editor), the output doesn't get generated right. Most > notably: > > - Only one plot created by myBarchart (or myBarchart2) gets saved, instead > of all 3 > - Some images are blank > > I'm having trouble isolating the problem to one line of code. > > I suspect there is some fundamental paradigm I'm not aware of about how R > devices and images work, perhaps relating to the importance of the order in > which the calls to png, dev.off(), etc. are executed, the required state of > my workspace before I run the code (e.g. whether the previous plot window > should be open or closed), or maybe even time dependency (do I need to > insert timed pauses so that my diagram has time to render before saving to a > file?). > > Does this ring a bell to anyone? I read the R documentation on devices and > png(), and searched the mailing list archives and the web, but haven't > figured out how to get this working. Any help would be appreciated. > > Thanks, > > Rex >I'm on Windows 7 and R 2.9.2, BTW. [[alternative HTML version deleted]]
If you are using lattice, check out FAQ 7.22 On Thu, Jan 14, 2010 at 5:15 PM, Rex C. Eastbourne <rex.eastbourne@gmail.com> wrote:> I am encountering problems using the png() function to save around 20 > charts > to separate files. > > My script is conceptually structured as follows: > > ### <script> > png("Image %03d.png") > > # the following are calls to user-defined functions I wrote that call plot, > barchart, etc. with special arguments. > myPlot("a") > myPlot("b") > myPlot("c") > > myBarchart("a") > myBarchart("b") > myBarchart("c") > > myBarchart2("a") > myBarchart2("b") > myBarchart2("c") > > dev.off() > ### </script> > > When I run the code a few lines at a time it generates the images > correctly. > However, when I execute all lines of the script at once (Ctrl+A, Ctrl+R in > the Rgui editor), the output doesn't get generated right. Most notably: > > - Only one plot created by myBarchart (or myBarchart2) gets saved, instead > of all 3 > - Some images are blank > > I'm having trouble isolating the problem to one line of code. > > I suspect there is some fundamental paradigm I'm not aware of about how R > devices and images work, perhaps relating to the importance of the order in > which the calls to png, dev.off(), etc. are executed, the required state of > my workspace before I run the code (e.g. whether the previous plot window > should be open or closed), or maybe even time dependency (do I need to > insert timed pauses so that my diagram has time to render before saving to > a > file?). > > Does this ring a bell to anyone? I read the R documentation on devices and > png(), and searched the mailing list archives and the web, but haven't > figured out how to get this working. Any help would be appreciated. > > Thanks, > > Rex > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]]