[R] blank pdf output when called in a loop

David Winsemius dwinsemius at comcast.net
Wed Jul 21 02:14:41 CEST 2010


On Jul 20, 2010, at 7:21 PM, Joshua Wiley wrote:

> 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) .

The interpreter handles finding the proper print methods. You just  
need to have a clear list in your mind regarding what is base graphics  
(e.g.plot)  and what is grid graphics (e.g. xyplot and qplot). This is  
part of the FAQ which points out that this also applies to any  
"source()"-ed code:

http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f

(which points out that this applies to ggplot2 functions as well.)

To further confuse the issue, not all functions named "plot" are  
dispatched to base graphics. Some are dispatched to lattice graphics.

-- 
David.


> 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/
>
> ______________________________________________
> 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