使用 -knitr- 在 RStudio 中编织 Rnw 文件

using -knitr- to weave Rnw files in RStudio

对于谁愿意在RStudio中使用knitr编写动态文档,这似乎是一个反复出现的问题(例如,另请参见here)。 不幸的是,我还没有在 Stack Overflow 上或通过谷歌搜索找到更多的解决方案。

这是我尝试在 RStudio 中编译的玩具示例。就是 minimal-example-002.Rnw (link):

\documentclass{article}
\usepackage[T1]{fontenc}

\begin{document}

Here is a code chunk.

<<foo, fig.height=4>>=
1+1
letters
chartr('xie', 'XIE', c('xie yihui', 'Yihui Xie'))
par(mar=c(4, 4, .2, .2)); plot(rnorm(100))
@

You can also write inline expressions, e.g. $\pi=\Sexpr{pi}$, and \Sexpr{1.598673e8} is a big number.

\end{document}

我的问题是我无法使用 knitrRStudio 中编译 pdf,而通过将默认编织选项更改为 sweave 我得到了最终的 pdf。

更具体地说,我在 Windows 7 中工作,最新的 RStudio 版本 (0.98.1103),我使用 knitr 选项编织文件并禁用了 "always enable Rnw concordance" 框。

你遇到过这种情况吗? 非常感谢任何帮助,非常感谢。

编辑

显然这不是 RStudio 问题,因为我试图从 R 编译文档:

library('knitr')
knit('minimal_ex.Rnw')

我得到同样的错误:

processing file: minimal_ex.Rnw

  |                                                                       
  |                                                                 |   0%
  |                                                                       
  |......................                                           |  33%
  ordinary text without R code


  |                                                                       
  |...........................................                      |  67%
label: foo (with options) 
List of 1
 $ fig.height: num 4

Quitting from lines 8-10 (minimal_ex.Rnw) 
Errore in data.frame(..., check.names = FALSE) : 
  arguments imply differing number of rows: 3, 0
Inoltre: Warning messages:
1: In is.na(res[, 1]) :
  is.na() applied to non-(list or vector) of type 'NULL'
2: In is.na(res) : is.na() applied to non-(list or vector) of type 'NULL'

编辑 2:

这是我的会话信息:

R version 3.1.1 (2014-07-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=Italian_Italy.1252  LC_CTYPE=Italian_Italy.1252    LC_MONETARY=Italian_Italy.1252 LC_NUMERIC=C                  
[5] LC_TIME=Italian_Italy.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] knitr_1.10.5

loaded via a namespace (and not attached):
[1] tools_3.1.1

在花了几个小时试图找出问题后,我更新了 R (v 3.2.0),现在一切正常。 目前尚不清楚问题是否是由于某些软件包冲突引起的,可以肯定这不是 RStudio 问题(正如我最初认为的那样)。

补充一点:这似乎是 echo 参数的错误,默认为 TRUE。使用 knitrpdfLaTeX 将其设置为 false 作为渲染器对我有用。如果您处于由于依赖项 and/or 权限问题而无法更新的情况,此输入可能是一个有用的临时修复程序,因为错误消息非常无用。