2

I am trying to include figures in my Sweave report. I have a file a.Rnw:

\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\begin{document}

<<echo=FALSE, fig=TRUE>>=
plot(c(1,3,5,2,4,2,4,2,42,3,2,3))
@

\end{document}

I generate the tex as:

$ R CMD Sweave a.Rnw 
Output file:  a.tex

However, no figure is generated.

$ pdflatex a.tex 
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013)
 restricted \write18 enabled.
...
! LaTeX Error: File `a-001' not found.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.11 \includegraphics{a-001}

? 

There is no such file

$ ls a-001*
ls: a-001*: No such file or directory

The generated tex is

\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}


\usepackage{Sweave}
\begin{document}

\includegraphics{a-001}

\end{document}

So how do I generate the figure?

highBandWidth
  • 16,751
  • 20
  • 84
  • 131
  • is the double-equals `==` after your chunk beginning a typo? – Ben Bolker May 22 '14 at 20:51
  • your code works for me, with and without the double = – rawr May 22 '14 at 20:52
  • Removed the extra = and I still don't get the figure. The Rnw works fine with knitr. Does Sweave require some specific graphics backend? – highBandWidth May 22 '14 at 21:35
  • I cannot reproduce either. Is there a file with the basename `a-001` being made in the folder? Probably `a-001.pdf`? You may have to set `\DeclareGraphicsExtensions{.pdf,.png,.jpg}` or something for LaTeX to look for the appropriate file for the appropriate output. – MrFlick May 23 '14 at 04:24
  • Nope, there is no file a-001*. KnitR works fine though so I am just using knitr. Still curious as to why this is so on my machine. – highBandWidth May 23 '14 at 19:18
  • Won't solve your mystery, but in my case what fixed it was removing the x11() command from the R syntax I was using to generate the new figures. I am adding this here because I got redirected after searching for the same problem and could help someone who is making the same mistake I did... – HelloWorld Nov 07 '19 at 10:37

0 Answers0