我得到奇怪的數字行爲。在一些塊中,knitr從單個繪圖函數生成兩個圖形,並且從'塊名'生成的圖形被命名爲「塊名1.1. pdf」和「塊名2.2.ddf」。有時候,第一個只是一個與第二個大小相同的空白圖形,有時卻是一個無法打開的文件。作爲解決辦法,我設置了fig.keep='last'
選項。但是現在我想顯示來自同一個塊的兩個圖並將fig.keep
設置爲其默認值,knitr生成3個PDF圖形文件,第一個文件是損壞的文件(無法打開)。knitr奇怪的失控行爲與數字
我已經Win7的64下knitr版本1.2(2013年4月10日)中,R 3.0.0版64位(2013年4月30日r62697)下面是我使用的設置:
knit_hooks$set(par = function(before, options, envir) {
if (before) par(mar = c(4, 4, .1, .1))
})
opts_knit$set(concordance=TRUE, self.contained=TRUE)
opts_chunk$set(fig.path="figSW/SW-", keep.source=FALSE,
verbose=TRUE, message=FALSE)
我無法用一個簡單的例子來重現它。然而,試圖創建這樣一個例子,我發現了其他奇怪的結果。在下面的示例中,只有曲線圖1,2和10被正確顯示,而其他所有曲線都沒有顯示(不生成PDF文件,並且不會在.tex文件中生成一致的\includegraphics
)。
\documentclass[12pt,a4paper]{article}
\begin{document}
Plot 1
<<test-t, echo=TRUE, results="asis", fig.width=10, fig.height=5>>=
x = c(1,2,3)
y = c(1,3,2)
plot(x,y)
@
Plot 2\\
<<test-tt, echo=FALSE, results="hide", fig.width=10, fig.height=5>>=
plot(x,y)
@
\newpage
Plot 3
<<test-s, echo=TRUE, results="asis", fig.width=10, fig.height=5>>=
x = c(1,2,3)
y = c(1,3,2)
plot(x,y)
@
Plot 4\\
<<test-ss, echo=FALSE, results="hide", fig.width=10, fig.height=5>>=
plot(x,y)
@
\newpage
Plot 5
<<test-r, echo=TRUE, results="asis", fig.width=10, fig.height=5>>=
x = c(1,2,3)
y = c(1,3,2)
plot(x,y)
@
Plot 6\\
<<test-rr, echo=FALSE, results="hide", fig.width=10, fig.height=5>>=
plot(x,y)
@
\newpage
Plot 7
<<test-v, echo=TRUE, results="asis", fig.width=10, fig.height=5>>=
x = c(1,2,3)
y = c(1,3,2)
plot(x,y)
@
Plot 8\\
<<test-vv, echo=FALSE, results="hide", fig.width=10, fig.height=5>>=
plot(x,y)
@
\newpage
Plot 9
<<test-u, echo=TRUE, results="asis", fig.width=10, fig.height=5>>=
x = c(1,2,3)
y = c(1,3,2)
plot(x,y)
@
Plot 10\\
<<test-uu, echo=FALSE, results="hide", fig.width=10, fig.height=5>>=
plot(x,y)
@
\end{document}
即使是陌生人,從R-Studio中編譯相同的文件,我得到了除積6至1,2和10
謝謝你,安裝開發版本解決了我的問題與空白和損壞的圖形文件。它還改善了重複塊的例子的結果。現在我可以看到所有的地塊,但3和4. – Gilbert
編譯從R-Studio與開發版本的knitr我可以看到所有的情節,但情節10. R-Studio說:「問題:1 badbox',但我不知道什麼這意味着。 – Gilbert
這個問題並不重要。 –