3
votes

I'm new to knitr and to Latex.

I keep getting the error "! LaTeX Error: File `figure/unnamed-chunk-1' not found." The error message says:

>! LaTeX Error: File `figure/unnamed-chunk-1' not found.
> See the LaTeX manual or LaTeX Companion for explanation.
> Type H <return> for immediate help.
...
> l.77 ...[width=\textwidth]{figure/unnamed-chunk-1}
> I could not locate the file with any of these extensions:
> .png,.pdf,.jpg,.mps,.jpeg,.jbig2,.jb2,.PNG,.PDF,.JPG,.JPEG,.JBIG2,.JB2,.eps

I have a simple tex file

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage[font={small}]{caption}
\author{My Name }
\title{knitr example}
\begin{document}
\maketitle

<<loading,echo=F>>=
library(ggplot2)
@

<< message=F,fig.width=9,fig.height=6,out.width='\\textwidth',cache= TRUE>>=
mydata  <- data.frame(year = seq(1901: 1950), debt = rnorm(50))
plot(mydata$year, mydata$debt, main = "Debt")
@
\end{document}  

I cannot seem to locate anything that seems relevant. Clearly "figure/unnamed-chunk-1" should be showing up somewhere but I don't see anything in the knitr options document to suggest a specific way to save it and so far I don't understand enough about knitr to figure out a way to name a plot to be imported.

1
I cannot reproduce the problem. Can you paste sessionInfo() after library(knitr)? Are all packages up-to-date? The only possible reason I can think of is that you ran it once before but deleted the figure directory later; since this chunk was cached, the plot will not be re-generated unless anything is changed. Does it work if you remove the option cache=TRUE?Yihui Xie

1 Answers

1
votes

It has been solved in the knitr mailing list. The problem was due to use of absolute paths in the output argument in knit(), so figures and tex output were not in the same directory. It is not recommended to use absolute paths in general; see more discussion in the mailing list.