R CMD检查不考虑编织代码块中的选择性代码评估 [英] R CMD check does not respect selective code evaluation in knitr code chunks

查看:101
本文介绍了R CMD检查不考虑编织代码块中的选择性代码评估的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Windows 7 32位(以及运行Windows 8 64位的另一台计算机上)的 R 3.1.0 中构建软件包,并且我正在使用编织以使用Markdown编写小插曲.我希望将此程序包发布在CRAN上,因此我正在使用R CMD检查来检查我的演示,数据集和小插图是否均正常运行.我将小插曲保存为 .Rmd文件(而不是将其作为包构建过程的一部分,而不是将它们存储在inst/doc中),因为它们可以作为我包中的额外测试,而且它们并不是很大.

I am building a package in R 3.1.0 on Windows 7 32-bit (and also on a different machine running Windows 8 64bit) and I am using knitr to write vignettes using Markdown. I am hoping to publish this package on CRAN so I am using R CMD check to check that my demos, datasets and vignettes all behave properly. I keep my vignettes as .Rmd files (rather than making them outside of the package building process and stashing them in inst/doc) because they serve as extra tests on my package and aren't very big anyway.

我的问题是,即使我先运行R CMD build然后再运行R CMD INSTALL,构建我的小插曲 R CMD检查也会失败.查看日志文件似乎失败了,因为它试图评估我明确告诉knitr不要评估的代码.作为一般示例,如果我写

My problem is that R CMD check fails when building my vignettes, even though if I run R CMD build and then R CMD INSTALL --build everything works out fine. Looking at the log file, it appears to be failing because it tries to evaluate code that I have explicitly told knitr NOT to evaluate. As a generic example, if I write

```{r example-chunk eval=c(1:3, 5:6), tidy=FALSE}
foo = 5
bar = 3
## don't evaluate the next line
file.show("i/dont/really/exist.csv")
## ok, start evaluating again
foobar = foo*bar
```

在.Rmd文件中,运行R CMD检查将失败,因为它将尝试评估第4行.但是,如果我先运行R CMD build mypackage然后进行R CMD install --build,则将正确评估该块. mypackage.tar.gz (我知道这一点,因为我可以转到我的Rlibs文件夹并在mypackage/doc中找到完美的html小插曲.类似地,如果运行R CMD Sweave,该块也将得到正确的评估. 来制作装饰图案.

In a .Rmd file, running R CMD check will fail because it will try to evaluate line 4. However, the chunk will be correctly evaluated if I run R CMD build mypackage and then R CMD install --build mypackage.tar.gz (I know this because I can go to my Rlibs folder and find the flawless html vignettes in mypackage/doc. Similarly, the chunk will also be evaluated correctly I if run R CMD Sweave to build the vignette.

如果您想自己尝试,我正在构建的软件包(我遇到问题的地方)在Github上:

If you want to try this yourself, the package I am building (where I am running into the issue) is on Github: https://github.com/mkoohafkan/flowdurr-edu. You can look at raw/packagemaker.html for instructions, hopefully it's straightforward (the R code runs through the process of making the package directory, building the help files and copying some manually edited files into the package directory). R CMD check fails on all of my vignettes: when building flowdurr-datasets.Rmd, it insists on evaluating a line with a fake path even though I told it not to. When building hspf-analysis.Rmd, R CMD check insists on evaluating a line I excluded because it takes a really long time to complete (using rgenoud to fit some distribution parameters). R CMD check also fails on vignette.Rmd, but for a different reason; I purposely throw errors to show examples of what you can't do with a particular function, and while knitr doesn't have a problem with it R CMD check sure does!

我的构建脚本越来越令人讨厌,所以我制作了这个虚拟包这在我的两台机器上都重现了该问题.它说明了1)R CMD检查会评估不应执行的行,2)R KMD检查不支持在小插图中进行错误评估,即使knitr会毫无问题地写入错误输出.

My build script was getting some hate so I made this dummy package that reproduced the problem on both of my machines. It illustrates that 1) R CMD check evaluates a line that it shouldn't, and 2) R CMD check does not support error evaluation in a vignette, even though knitr will write error output without issue.

所以我想我的问题是:在进行小插图构建时,R CMD检查与R CMD Sweave和R CMD构建/安装有何不同?使R CMD检查针织机的评估"规格? 请注意,如果我使用eval = FALSE,则R CMD检查将尊重它,一切都很好;仅当我尝试对块进行选择性评估时,才会出现该问题.

So I guess my question is: What is it that R CMD check is doing differently from R CMD Sweave and R CMD build/install when it comes to vignette building, and is there anything I can do to make R CMD check respect knitr's 'eval' specification? Note that if I use eval=FALSE, R CMD check will respect it and everything is fine; the problem only occurs if I try selective evaluation of a chunk.

推荐答案

我已经添加了 knitr 开发版本1.6.2中带有后缀_notangle的>小插图引擎.对于原始的小插图引擎knitr::foo,您可以使用新的引擎knitr::foo_notangle禁用缠结(例如knitr::knitr_notangleknitr::rmarkdown_notangle,...).

I have added vignette engines with the suffix _notangle in the knitr development version 1.6.2. For the original vignette engine knitr::foo, you can use the new engine knitr::foo_notangle to disable tangle (e.g. knitr::knitr_notangle, knitr::rmarkdown_notangle, ...).

如果您不想等待下一个版本的 knitr 进入CRAN(可能需要一段时间),则可以肯定地

If you do not want to wait for the next version of knitr to be on CRAN (which might take a while), you can certainly register a package vignette engine by yourself. Hint: you can make use of existing engines in tools::vignetteEngine(package = 'knitr') so you do not have to completely redefine the knitr vignette engines.

这篇关于R CMD检查不考虑编织代码块中的选择性代码评估的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆