Hi R people I am using a function to create a pdf device, then send a lot of plots to it in a loop then a last lattice xyplot (itself within a function) outside the loop and finally call dev.off() to write to the file. This works well apart from the fact that the last plot does not get sent to the file unless I comment out dev.off() and then apply it in the console afterwards instead: plot_stuff( ...); dev.off() The device is opened like this: pdf( paste( var_string, ".pdf", sep="" ), onefile=TRUE, paper="a4r", width=9, height=6.5 ) Also, if I try to send two different xyplots after the loop only the last one ever gets written to the file, whether or not I apply the dev.off() trick above. Any thoughts on why this stuff happens and best ways to avoid it are appreciated. Other info -> R 2.7.1 on Intel Mac 10.5.3. TIA Michael ______________________________________________ Hopkins Research Touch the Future ______________________________________________ [[alternative HTML version deleted]]
Michael Hopkins wrote:> Hi R people > > I am using a function to create a pdf device, then send a lot of plots > to it in a loop then a last lattice xyplot (itself within a function) > outside the loop and finally call dev.off() to write to the file. > This works well apart from the fact that the last plot does not get > sent to the file unless I comment out dev.off() and then apply it in > the console afterwards instead: > > plot_stuff( ...); dev.off() >dev.off() shouldn't care where it is being called from. Please post (short!) reproducible code to show your glitch. Duncan Murdoch> The device is opened like this: > > pdf( paste( var_string, ".pdf", sep="" ), onefile=TRUE, paper="a4r", > width=9, height=6.5 ) > > Also, if I try to send two different xyplots after the loop only the > last one ever gets written to the file, whether or not I apply the > dev.off() trick above. > > Any thoughts on why this stuff happens and best ways to avoid it are > appreciated. > > Other info -> R 2.7.1 on Intel Mac 10.5.3. > > TIA > > Michael > > ______________________________________________ > > Hopkins Research Touch the Future > ______________________________________________ > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >
On 7/1/08, Michael Hopkins <michael.hopkins at hopkins-research.com> wrote:> > > Hi R people > > I am using a function to create a pdf device, then send a lot of plots > to it in a loop then a last lattice xyplot (itself within a function) > outside the loop and finally call dev.off() to write to the file. > This works well apart from the fact that the last plot does not get > sent to the file unless I comment out dev.off() and then apply it in > the console afterwards instead: > > plot_stuff( ...); dev.off() > > The device is opened like this: > > pdf( paste( var_string, ".pdf", sep="" ), onefile=TRUE, paper="a4r", > width=9, height=6.5 ) > > Also, if I try to send two different xyplots after the loop only the > last one ever gets written to the file, whether or not I apply the > dev.off() trick above. > > Any thoughts on why this stuff happens and best ways to avoid it are > appreciated.This sounds like FAQ 7.22: http://cran.us.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f The dev.off() issue is most likely a red herring; the important bit is that the xyplot() call was not the last expression in your function. -Deepayan
Are you explicitly 'print'ing the lattice plot? print(xyplot(...)) On Tue, Jul 1, 2008 at 6:20 AM, Michael Hopkins <michael.hopkins at hopkins-research.com> wrote:> > > Hi R people > > I am using a function to create a pdf device, then send a lot of plots > to it in a loop then a last lattice xyplot (itself within a function) > outside the loop and finally call dev.off() to write to the file. > This works well apart from the fact that the last plot does not get > sent to the file unless I comment out dev.off() and then apply it in > the console afterwards instead: > > plot_stuff( ...); dev.off() > > The device is opened like this: > > pdf( paste( var_string, ".pdf", sep="" ), onefile=TRUE, paper="a4r", > width=9, height=6.5 ) > > Also, if I try to send two different xyplots after the loop only the > last one ever gets written to the file, whether or not I apply the > dev.off() trick above. > > Any thoughts on why this stuff happens and best ways to avoid it are > appreciated. > > Other info -> R 2.7.1 on Intel Mac 10.5.3. > > TIA > > Michael > > ______________________________________________ > > Hopkins Research Touch the Future > ______________________________________________ > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?