[R] Sweave with pdf(): how to remove mention "null device"

Kevin E. Thorpe kevin.thorpe at utoronto.ca
Thu Jan 27 14:17:32 CET 2011


Hi there.

Out of curiosity, why are you doing it that way instead of this:

<<fig=TRUE,echo=FALSE>>=
plot(runif(100))
@

Kevin

On January 27, 2011 05:30:08 am Matthieu Stigler wrote:
> great, solved! Thanks a lot for your quick help!
>
> Le 27. 01. 11 11:22, Prof Brian Ripley a écrit :
> > Note that the 'problem' is with dev.off(), not pdf(), and the answer
> > is ?invisible.
> >
> > pdf()
> > invisible(dev.off())
> >
> > On Thu, 27 Jan 2011, Matthieu Stigler wrote:
> >> Hi
> >>
> >> I am sorry, my question seems simple and must already have been
> >> asked, but I did not find any aswser on the archives :-(
> >
> > Searching for the irrelevant 'pdf()' will not have helped, I fear ...
> >
> >> I am trying to use a plot in Sweave, where I include myself the
> >> statement
> >> <<results=tex,echo=FALSE>>=
> >> pdf("plot.pdf")
> >> plot(runif(100))
> >> dev.off()
> >> cat("\\includegraphics{plot}\n\n")
> >>
> >> @
> >>
> >> as is documented in the Sweave user guide A.9. The problem is that a
> >> "null device 0" is printed in my document! Indeed, each time one
> >> opens pdf() or any device, some mention "pdf" inevitably shows up...
> >> try:
> >>
> >> pdf()
> >> plot(runif())
> >> dev.off()
> >>
> >> How can one get rid of this? The only workaround I found is to place
> >> it into a if() loop:
> >>
> >> for(i in 1:1){
> >> pdf()
> >> plot(runif())
> >> dev.off()
> >> }
> >>
> >> so there is no track of the mention null device, and my sweave pdf
> >> looks better. Any idea of a more elegant solution?
> >>
> >> Thanks!!
> >>


-- 
Kevin E. Thorpe
Biostatistician/Trialist, Knowledge Translation Program
Assistant Professor, Dalla Lana School of Public Health
University of Toronto
email: kevin.thorpe at utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016



More information about the R-help mailing list