When I use pdf("somefile.pdf")
to save my plots to a pdf file, everything seems to work. No error messages or whatsoever. Still the result is screwed (file size is NOT 0 KB) but I can't open it using preview nor adobe reader. I am running Mac OS 10.6 and the latest R Studio release. Any suggestions? Note png()
works perfectly fine, so does sweave and pdf plots from ggplot.
Asked
Active
Viewed 3,365 times
0

Matt Bannert
- 27,631
- 38
- 141
- 207
-
1@Roman: your new title is a little misleading since the OP says the file size is not 0K ... – Ben Bolker Jun 27 '11 at 15:12
-
Actually re-edited it, because it's definitely not zero. – Matt Bannert Jun 27 '11 at 15:14
-
Thanks. I misread ran2, as I often get 0k size if I forget to `dev.off()`. – Roman Luštrik Jun 27 '11 at 23:15
2 Answers
7
Did you remember to close the file via dev.off()
before trying to view it?
(See also: problem saving pdf file in R with ggplot2 )

Community
- 1
- 1

Ben Bolker
- 211,554
- 25
- 370
- 453
-
Thx Ben. Note that I have to wait 6 minutes before I am allowed to accept this lightning quick AND helpful answer. Somehow must have missed that. I wonder whether I closed it when I viewed the png. However, thx! Must have missed that somehow. – Matt Bannert Jun 27 '11 at 14:32
-
It's entirely possible that PDF and PNG have different characteristics in the way that they write information about plots to disk, so PNG may be more robust to viewing an unclosed plot. You could experiment if you cared enough to find out ... – Ben Bolker Jun 27 '11 at 14:34
1
The pdf and png devices work a little different. The pdf device by default will put multiple plots into a single file, so it will not finalize the file until you tell it that you are finished creating the plots (with dev.off). The png device will put 1 plot in 1 file, so will create multiple files for multiple plots. So as soon as you start a second plot, the 1st file will be finalized and can be opened and used. You still need dev.off to finalize the last file after the last plot.

Greg Snow
- 48,497
- 6
- 83
- 110