knitr和Sweave生成的pdf文件名已编号

时间:2014-10-26 17:34:24

标签: pdf knitr options

如果我写一个简单的Rnw文档,其中包含例如

之类的数字
\documentclass[11pt]{article}

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<<setup, include=FALSE, cache=FALSE>>=
opts_chunk$set(dev = "pdf", comment = NA, fig.path = "figure/", fig.align='center', cache=FALSE, message=FALSE, background='white')
options(replace.assign=TRUE,width=85, digits = 8)
knit_hooks$set(fig=function(before, options, envir){if (before) par(mar=c(4,4,.1,.1),cex.lab=.95,cex.axis=.9,mgp=c(2,.7,0),tcl=-.3)})
@

<<prepare-data, include=FALSE>>=
@
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\begin{document}

A simple plot
\begin{figure}
<< scat, echo = FALSE, fig.width = 4.5, fig.height=3>>=
plot(runif(10), runif(10), pch = 20)
@
\end{figure}
\end{document} 

为什么现在knitr创建了一个pdf文件figure/scat-1.pdf而不是figure/scat.pdf

1 个答案:

答案 0 :(得分:0)

v1.7 release notes解释了原因。在开发版本(即v1.8)中,您可以使用fig_chunk()来获取图形文件名(请参阅包NEWS)。另请参阅相关讨论here