Question

If a pdf document is created using the following Sweave (R/LaTeX) code, then in the top left of the figure there will be text pdf 2; note this is not embedded in the png but is actually text you can highlight.

In the .Rnw:

\begin{figure}[htb]
    \centering
<<fig=FALSE,echo=FALSE>>=
    png("test0.png",width=4,height=4,units='in',res=1200)
    plot(1)
    dev.off()
@
    \includegraphics{test0.png}
    \caption{Demonstration}
\end{figure}

Then in R:

Sweave("report.Rnw") ; texi2pdf("report.tex")

How do I fix this?

I am using a very recent version of R on Ubuntu.

Était-ce utile?

La solution

With the following file

\documentclass{article}
\begin{document}
\begin{figure}[htb]
    \centering
<<fig=FALSE,echo=FALSE>>=
    png("test0.png",width=4,height=4,units='in',res=1200)
    plot(1)
    dev.off()
@
    \includegraphics{test0.png}
    \caption{Demonstration}
\end{figure}

there is a null device 1 message that appears before the plot It is the output of the R commands that generate the plot. You can suppress it by adding results=hide.

<<fig=FALSE,echo=FALSE,results=hide>>=

Your message is slightly different because dev.off() returns the name of the current device: there was none in my case (it was a fresh session), and a previously opened (but not closed) PDF file in your case.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top