[R] blank pdf output when called in a loop

Joshua Wiley jwiley.psych at gmail.com
Wed Jul 21 01:21:59 CEST 2010


Hi Nicolas,

You nee to explicitly wrap it in print() when it is inside a loop (if
I'm not mistaken also when inside a function).  With lattice loaded,
you can find the specific print methods by methods(print) .  From your
example:

pdf("temp1.pdf", width=8, height=8)
for(k in 1) {
print(wireframe(volcano))
}
dev.off()

HTH,

Josh

On Tue, Jul 20, 2010 at 4:02 PM, Nicolas STRANSKY
<stransky at broadinstitute.org> wrote:
> Hi,
>
> I'm hitting a strange problem where pdf plots that I'm trying to make
> are blank, only when produced from within a loop. The pdf contains 0 page.
> I've narrowed the problem to this minimal script that invariably
> produces an empty pdf with my setup:
> pdf("/local/scratch/1.pdf", width=8, height=8)
> for (k in 1) {
>  wireframe(volcano)
> }
> dev.off()
>
> The odd thing is that
> pdf("/local/scratch/1.pdf", width=8, height=8)
>  wireframe(volcano)
> dev.off()
> works fine!
>
> Am I doing something wrong here? I've tried on two different systems,
> Linux or Mac.
>
> Thanks,
>    Nico
>
>
> R version 2.11.0 (2010-04-22)
> x86_64-unknown-linux-gnu
>
> locale:
>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
> LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=C
>
>  [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C
>              LC_ADDRESS=C               LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] lattice_0.18-5 custom_1.1
>
> loaded via a namespace (and not attached):
> [1] grid_2.11.0
>
> --
> Nicolas STRANSKY, Ph.D.
> Computational Biologist, Cancer Program
> Broad Institute of MIT and Harvard
> 5CC-1339  |  7 Cambridge Center  |  Cambridge, MA  02142, USA
> Phone: +1 617 714 7564           |    nico at BroadInstitute.org
>
> ______________________________________________
> 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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list