user1839752
user1839752

Reputation: 31

knitr -- ! LaTeX Error: File `figure/unnamed-chunk-1' not found

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.

Upvotes: 3

Views: 5474

Answers (2)

An old question, but it I stumbled the issues recently, whether on MacOS or Win. I have tried the solution above but didn't work. What works for me is to delete all the figure inside figure-latex folder and re-run the knit.

Upvotes: 1

Yihui Xie
Yihui Xie

Reputation: 30194

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.

Upvotes: 1

Related Questions