简体   繁体   English

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

[英]using -knitr- to weave Rnw files in RStudio

This seems to be a recurrent problem for who is willing to write dynamic documents with knitr in RStudio (see also here for instance). 这似乎是一个经常出现的问题,谁愿意在RStudio使用knitr编写动态文档(例如也参见此处 )。 Unfortunately I haven't find a solution on Stack Overflow or by googling more in general. 不幸的是,我没有在Stack Overflow上找到解决方案,也没有通过Google搜索更多。

Here is a toy example I am trying to compile in RStudio. 这是我试图在RStudio中编译的玩具示例。 It is the minimal-example-002.Rnw ( link ): 它是minimal-example-002.Rnw链接 ):

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

My problem is that I am not able to compile the pdf in RStudio by using knitr , while by changing the default weaving option to sweave I get the final pdf. 我的问题是我无法使用knitrRStudio编译pdf,而通过将默认编织选项更改为sweave我得到了最终的pdf。

More specifically, I work in Windows 7, latest RStudio version (0.98.1103), I weave the file using the knitr option and I disabled the "always enable Rnw concordance" box. 更具体地说,我使用Windows 7,最新的RStudio版本(0.98.1103),我使用knitr选项编织文件,并禁用“始终启用Rnw一致性”框。

Did this happen to you? 这件事发生在你身上吗? Any help would be highly appreciated, thank you very much. 非常感谢任何帮助,非常感谢。

EDIT 编辑

Apparently it is not an RStudio problem, as I tried to compile the document from R with: 显然它不是一个RStudio问题,因为我试图从R编译文档:

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

and I get the same error: 我得到同样的错误:

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'

EDIT 2: 编辑2:

This is my session info: 这是我的会话信息:

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

After spending hours to try to figure out the problem, I updated R (v 3.2.0) and everything works fine now. 在花了好几个小时试图找出问题之后,我更新了R(v 3.2.0),现在一切正常。 It is not clear if the problem was due to some packages conflict, for sure it wasn't an RStudio problem (as I had initially thought). 目前尚不清楚这个问题是否是由于某些软件包冲突造成的,当然这不是一个RStudio问题(正如我最初想的那样)。

To add a little to this: It seems to be a bug with the echo parameter which defaults to TRUE . 添加一点:这似乎是echo参数的一个错误,默认为TRUE Setting it to false with knitr and pdfLaTeX as a renderer worked for me. 使用knitrpdfLaTeX作为渲染器将其设置为false对我pdfLaTeX In case you're in a situation where you can't update because of dependencies and/or rights issues, this input might be a helpful adhoc fix, since the error message is pretty useless. 如果您因为依赖性和/或权限问题而无法更新,则此输入可能是一个有用的特殊修复,因为错误消息非常无用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM