Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

latex

knitr

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.

like image 569
user1839752 Avatar asked Jan 25 '26 20:01

user1839752


1 Answers

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.

like image 157
Yihui Xie Avatar answered Jan 27 '26 12:01

Yihui Xie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!