为CRAN包创建简短示例。

[英]Creating short examples for CRAN package


I'm currently building a package that I hope to upload to CRAN. The examples I've included in my help documentation currently take some time to check (~12min in total), and I'm aware that this can be an issue when trying to load on CRAN. While I could make my examples run faster, I'm worried this will make them less meaningful for users reading the help files. Is there a way to include some fast (but less meaningful) examples that will be checked by CRAN but won't be visible to users in the help documentation?

我目前正在构建一个包,我希望上传到CRAN。我在帮助文档中包含的示例目前需要花费一些时间检查(总共大约12分钟),我知道在尝试加载CRAN时这可能是一个问题。虽然我可以使示例运行得更快,但我担心这将使阅读帮助文件的用户不太有意义。是否有一种方法可以包含一些快速(但不那么有意义)的示例,这些示例将由CRAN进行检查,但在帮助文档中不会对用户可见?

I'm using devtools and roxygen2 to write my documentation, so it would be great to get an answer using these tools if possible.

我正在使用devtools和roxygen2来编写我的文档,所以如果可能的话,使用这些工具来得到一个答案会很好。

Thanks for your help.

谢谢你的帮助。

3 个解决方案

#1


2  

Sounds like you would like to do some unit testing, which is a very good idea when working with more complex packages. Check out the testthat package (article, source).

听起来你想做一些单元测试,这在处理更复杂的包时是一个很好的主意。查看testthat包(文章、源代码)。

Short and purely technical examples that are needed to ensure correct operation of your package, but not very relevant to the end user, would then go into a separate folder myPackage/tests. These will automatically be run every time you build the package, but will not be included in the documentation files.

为了确保您的包的正确操作,但与最终用户不太相关,需要做简短的纯技术示例,然后再进入一个单独的文件夹myPackage/tests。这些将在每次构建包时自动运行,但不会包含在文档文件中。

The recommended solution is to make a file called myPackage/tests/run-all.R:

推荐的解决方案是制作一个名为myPackage/tests/run-all的文件:

library(testthat)
library(myPackage)
test_package("myPackage")

then put all the testing code in myPackage/tests/testthat, e.g. myPackage/tests/testthat/foo.R:

然后将所有测试代码放入myPackage/tests/testthat,例如myPackage/tests/testthat/foo.R:

context("Basic operation")

test_that("Default execution", {
    a <- 4
    b <- 34
    expect_equal(myFunction(a, b), a + b)
})

The reason for putting the tests in myPackage/tests/testthat rather than directly in myPackage/tests is that myPackage/tests/testthat will be included in the final package (albeit in a different folder) which allows the user to also run the tests. myPackage/tests will not be copied to the final package.

将测试放在myPackage/tests/testthat而不是直接放在myPackage/tests中的原因是,myPackage/tests/ test将包含在最终的包中(尽管是在不同的文件夹中),这允许用户也运行测试。myPackage/tests不会被复制到最终的包中。

#2


1  

See the manual, section 2.1.1, example subsection. You can enclose your more heavy examples into \dontrun and they will not be checked.

参见手册,第2.1.1节,示例小节。你可以把你比较重的例子放在\dontrun中,它们不会被检查。

#3


0  

If the only problem is CRAN loading, you should use \donttest{} command to prevent running the examples on CRAN. Note that the examples will still run when the user type example(xx)

如果唯一的问题是CRAN加载,您应该使用\donttest{}命令来防止在CRAN上运行示例。注意,当用户类型示例(xx)

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2015/02/26/bad86258e47c11416e2c430a26439409.html



猜您在找
Excel VBA的最佳简短示例 - Best short examples of the need for Excel VBA 使用pyseries包的完整示例。 - Full examples of using pySerial package 检查从CRAN安装软件包的次数 - Check how many times a package was installed from CRAN 如何安装不在CRAN存储库中的软件包? - How to install a package not located on CRAN repository? 如何让CRAN自动安装包依赖项? - How to tell CRAN to install package dependencies automatically?
智能推荐
 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告