3

我是 knitr 和 Latex 的新手。

我不断收到错误“!LaTeX 错误:找不到文件‘figure/unnamed-chunk-1’。” 错误消息说:

>! 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

我有一个简单的 tex 文件

\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}  

我似乎找不到任何似乎相关的东西。显然“figure/unnamed-chunk-1”应该出现在某处,但我在 knitr options 文档中没有看到任何建议保存它的具体方法,到目前为止,我对 knitr 的了解还不够,无法弄清楚命名要导入的绘图的方法。

4

2 回答 2

1

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.

于 2012-11-22T17:22:48.550 回答
0

一个老问题,但我最近偶然发现了这些问题,无论是在 MacOS 还是 Win 上。我已经尝试了上面的解决方案,但没有奏效。对我有用的是删除figure-latex文件夹内的所有图形并重新运行编织。

于 2021-10-13T02:40:37.657 回答