简体   繁体   English

RStudio的knitr编译问题(Windows)

[英]knitr compile problems with RStudio (windows)

i have a knitr based Rnw file that is compiling to pdf perfectly fine in RStudio on mac (v0.97.316) and knitr (v1.1) but in a windows enviornment (same versions) i get a compilation error. 我有一个基于knitr的Rnw文件,可以在Mac(v0.97.316)和knitr(v1.1)上的RStudio中将其编译为pdf很好,但是在Windows环境(相同版本)中却遇到编译错误。 I've checked the options in RStudio in both environments and they are consistent. 我已经在两种环境中检查了RStudio中的选项,它们是一致的。

It appears that the windows setup is always injecting: "\\SweaveOpts{concordance=TRUE}" into the ".tex" file even though i have no such flag in the Rnw file, and/or if i toggle the settings in the preferences, and/or if i add the "opts_knit$set(concordance=FALSE)" options to a knitr settings chunk. Windows安装程序似乎总是向“ .tex”文件中注入“ \\ SweaveOpts {concordance = TRUE}”,即使我在Rnw文件中没有这样的标志,并且/或者如果我在首选项中切换了设置,和/或如果我将“ opts_knit $ set(concordance = FALSE)”选项添加到针织设置块中。 If i drop the line from the ".tex" file and compile it manually at the cmd prompt the output is generated as expected. 如果我从“ .tex”文件中删除该行,并在cmd提示符下手动对其进行编译,则将按预期生成输出。

I'm not sure if this is an RStudio or knitr problem, but any pointers would be appreciated. 我不确定这是RStudio还是knitr问题,但是任何指针都将不胜感激。

Note, i've also posted this question on the RStudio support board ( http://support.rstudio.org/help/discussions/problems/5039-knitr-compile-problems-with-rstudio-windows?unresolve=true ). 请注意,我还将这个问题发布在RStudio支持板上( http://support.rstudio.org/help/discussions/problems/5039-knitr-compile-problems-with-rstudio-windows?unresolve=true )。

The reason that it was injecting \\SweaveOpts{concordance=TRUE} is likely to be your weaver was Sweave instead of knitr , and you also enabled Rnw concordance: http://www.rstudio.com/ide/docs/authoring/rnw_weave But I cannot say for sure it is not a bug for the Windows version of RStudio. 它注入\\SweaveOpts{concordance=TRUE}原因很可能是您的织布工,是Sweave而不是knitr ,并且还启用了Rnw一致性: http ://www.rstudio.com/ide/docs/authoring/rnw_weave但是我不能肯定地说这不是Windows版本的RStudio的错误。 Anyway, it is easy to verify if it is an RStudio problem -- open the Compile PDF panel and you should see the log like this: 无论如何,很容易验证是否是RStudio问题-打开“ Compile PDF面板,您应该看到如下日志:

带有编织器的RStudio

If your weaver was Sweave, you will see something like this instead: 如果您的编织者是编织者,那么您将看到类似以下内容:

带Studio的RStudio

This is my configuration (I'm under Ubuntu): 这是我的配置(我在Ubuntu下):

在RStudio中配置Sweave

If you are using knitr indeed, and RStudio still inserts \\SweaveOpts{concordance=TRUE} , I guess it must be a bug of RStudio. 如果确实使用了knitr ,并且RStudio仍然插入\\SweaveOpts{concordance=TRUE} ,那么我猜它一定是RStudio的错误。

I encountered this problem with "R CMD build KFAS-master" downloaded 2016-04-24 as "KFAS-master.zip" clicking "Download ZIP" from KFAS on GitHub ( https://github.com/helske/KFAS ). 我在“ R CMD build KFAS-master”下载为2016年4月24日以“ KFAS-master.zip”的形式单击此问题,并单击了从GitHub( https://github.com/helske/KFAS )上的KFAS下载“ ZIP”。 I'm unable to replicate the problem, but the work around I used was to find the line mentioned in the pop-up (copied below), and comment it out by preceding it with "%%". 我无法复制该问题,但是我所使用的解决方法是找到弹出窗口中提到的行(在下面复制),并在其前面加上“ %%”以将其注释掉。

After downloading it, I unzipped it and changed the name of the folder to "KFAS". 下载后,我将其解压缩并将文件夹名称更改为“ KFAS”。 Then I got a command prompt and navigated to the directory containing the KFAS-master folder renamed as KFAS. 然后,我得到一个命令提示符,并导航到包含重命名为KFAS的KFAS-master文件夹的目录。 This time "R CMD build KFAS" worked as expected. 这次“ R CMD建立KFAS”按预期工作。 Then I opened ~KFAS/vignettes/KFAS.Rmw in RStudio 0.99.893, the current version as of 2016-04-26. 然后我在RStudio 0.99.893(截至2016-04-26的当前版本)中打开〜KFAS / vignettes / KFAS.Rmw。 I changed something and saved the result. 我更改了一些内容并保存了结果。 When I repeated "R CMD build KFAS", I got the problem portrayed in the image below. 当我重复“ R CMD build KFAS”时,我得到了下图所示的问题。

Jouni Helske directed me to this post. Jouni Helske将我引导至该职位。 I commented out line 69 mentioned in the screen shot below by prepending "%%" to "\\SweaveOpts{concordance=TRUE}". 我通过将“ %%”添加到“ \\ SweaveOpts {concordance = TRUE}”之前,注释掉了下面屏幕截图中提到的第69行。 I saved the result, and "R CMD build KFAS" worked. 我保存了结果,“ R CMD建立KFAS”成功了。

Something seems to occasionally insert a line like "\\SweaveOpts{concordance=TRUE}" into a *.Rnw file, but I don't know what it is. 似乎偶尔会在* .Rnw文件中插入“ \\ SweaveOpts {concordance = TRUE}”这样的行,但我不知道它是什么。 I'm running R 3.2.4 on a MacBook Pro with OS X 10.11.2. 我在装有OS X 10.11.2的MacBook Pro上运行R 3.2.4。

Thanks to Yihui and others for earlier posts in this thread. 感谢Yihui和其他人在此主题中的早期文章。

screen shot showing pop-up complaining, "It seems you are using the Sweave-specific syntax in line(s) 69... ." 该屏幕快照显示弹出窗口抱怨:“似乎您在第69行...中使用的是Sweave特定的语法。”

I had the same problem even when knitr was set for "Weave Rnw files using" by default. 即使在默认情况下为“使用...编织Rnw文件”设置了knitr时,我也遇到了同样的问题。

I solved it by going to Tools/Global Options/Sweave and setting "Weave Rnw files using" to Sweave and pressing Ok . 我通过转到工具/全局选项/ Sweave并将“使用Weave Rnw文件使用”设置为Sweave并按Ok Then, I went back and set it back to knitr , and everything works fine now. 然后,我返回并将其设置为knitr ,现在一切正常。

I guess it was indeed Rstudio bug 我想这确实是Rstudio错误

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

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