R CMD check自动运行位于tests/目录中的测试。然而,以这种方式运行测试需要首先构建软件包。之后,R CMD check在最终到达测试之前会进行各种不同的健全性检查。
R CMD check
tests/
**问题:**是否有一种方法可以运行这些测试,而无需首先构建或安装软件包?
注:不使用testthat或其他非标准封装。
testthat
mbjcgjjk1#
总结一下我们的讨论。1.据我所知,对于base R提供的单元测试,没有R CMD check的标准替代品1.通常对于单元测试,我在R/下获取所有内容(在source/下获取dyn.load所有内容),然后在tests/下获取所有内容(实际上,我还使用man/目录中帮助页面的Example部分作为测试用例,并将其结果与以前的包版本进行比较)。我假设这些是devtools和testthat提供的基本测试功能。如果您希望开发多个包并希望独立于非base-R,我建议使用自定义脚本/包自动化上述过程。我会重新评论一下http://r-pkgs.had.co.nz/tests.html。
R/
source/
man/
Example
devtools
qjp7pelc2#
测试一个包而不需要
安装到临时目录tmp.lib中,并使用tools::testInstalledPackage在第二个临时目录tmp.out中测试 * 该 * 安装:
tmp.lib
tools::testInstalledPackage
tmp.out
pkg.name <- "Matrix" pkg.root <- normalizePath(file.path("path", "to", pkg.name), mustWork = TRUE) # an absolute path (?) tmp.lib <- tempfile() tmp.out <- tempfile() dir.create(tmp.lib) dir.create(tmp.out) owd <- setwd(tmp.out) tools::Rcmd(c("build", pkg.root))
* checking for file '/x/y/z/path/to/Matrix/DESCRIPTION' ... OK . . . * building 'Matrix_1.5-5.tar.gz'
list.files(tmp.out)
[1] "Matrix_1.5-5.tar.gz"
tools::Rcmd(c("INSTALL", "-l", tmp.lib, "--install-tests", "*.tar.gz"))
* installing *source* package 'Matrix' ... . . . * DONE (Matrix)
list.files(tmp.lib)
[1] "Matrix"
tools::testInstalledPackage(pkg.name, lib.loc = tmp.lib, types = "tests")
Running specific tests for package 'Matrix' Running 'Class+Meth.R' Running 'Simple.R' Running 'abIndex-tsts.R' Running 'base-matrix-fun.R' Running 'bind.R' comparing 'bind.Rout' to 'bind.Rout.save' ... OK Running 'dg_Matrix.R' Running 'dpo-test.R' Running 'dtpMatrix.R' Running 'factorizing.R' Running 'group-methods.R' Running 'indexing.R' comparing 'indexing.Rout' to 'indexing.Rout.save' ... OK Running 'matprod.R' Running 'matr-exp.R' Running 'other-pkgs.R' Running 'packed-unpacked.R' Running 'spModel.matrix.R' Running 'symmDN.R' Running 'validObj.R' Running 'write-read.R'
list.files(tmp.out, recursive = TRUE)
[1] "Matrix-tests/Class+Meth.R" "Matrix-tests/Class+Meth.Rout" [3] "Matrix-tests/Rplots.pdf" "Matrix-tests/Simple.R" [5] "Matrix-tests/Simple.Rout" "Matrix-tests/abIndex-tsts.R" [7] "Matrix-tests/abIndex-tsts.Rout" "Matrix-tests/base-matrix-fun.R" [9] "Matrix-tests/base-matrix-fun.Rout" "Matrix-tests/bind.R" [11] "Matrix-tests/bind.Rout" "Matrix-tests/bind.Rout.save" [13] "Matrix-tests/dg_Matrix.R" "Matrix-tests/dg_Matrix.Rout" [15] "Matrix-tests/dpo-test.R" "Matrix-tests/dpo-test.Rout" [17] "Matrix-tests/dtpMatrix.R" "Matrix-tests/dtpMatrix.Rout" [19] "Matrix-tests/factorizing.R" "Matrix-tests/factorizing.Rout" [21] "Matrix-tests/group-methods.R" "Matrix-tests/group-methods.Rout" [23] "Matrix-tests/indexing.R" "Matrix-tests/indexing.Rout" [25] "Matrix-tests/indexing.Rout.save" "Matrix-tests/matprod.R" [27] "Matrix-tests/matprod.Rout" "Matrix-tests/matr-exp.R" [29] "Matrix-tests/matr-exp.Rout" "Matrix-tests/mm-Matrix.tab" [31] "Matrix-tests/other-pkgs.R" "Matrix-tests/other-pkgs.Rout" [33] "Matrix-tests/packed-unpacked.R" "Matrix-tests/packed-unpacked.Rout" [35] "Matrix-tests/spModel.matrix.R" "Matrix-tests/spModel.matrix.Rout" [37] "Matrix-tests/symmDN.R" "Matrix-tests/symmDN.Rout" [39] "Matrix-tests/validObj.R" "Matrix-tests/validObj.Rout" [41] "Matrix-tests/write-read.R" "Matrix-tests/write-read.Rout" [43] "Matrix_1.5-5.tar.gz"
setwd(owd) unlink(tmp.out) unlink(tmp.lib)
当然,您可能希望将所有这些都放入一个函数中,最好带有一个选项,以 not 销毁输出目录,这样您就可以根据需要检查.Rout文件和任何.Rout.fail文件。
.Rout
.Rout.fail
2条答案
按热度按时间mbjcgjjk1#
总结一下我们的讨论。
1.据我所知,对于base R提供的单元测试,没有
R CMD check
的标准替代品1.通常对于单元测试,我在
R/
下获取所有内容(在source/
下获取dyn.load所有内容),然后在tests/
下获取所有内容(实际上,我还使用man/
目录中帮助页面的Example
部分作为测试用例,并将其结果与以前的包版本进行比较)。我假设这些是
devtools
和testthat
提供的基本测试功能。如果您希望开发多个包并希望独立于非base-R,我建议使用自定义脚本/包自动化上述过程。我会重新评论一下http://r-pkgs.had.co.nz/tests.html。
qjp7pelc2#
测试一个包而不需要
R CMD check
安装到临时目录
tmp.lib
中,并使用tools::testInstalledPackage
在第二个临时目录tmp.out
中测试 * 该 * 安装:当然,您可能希望将所有这些都放入一个函数中,最好带有一个选项,以 not 销毁输出目录,这样您就可以根据需要检查
.Rout
文件和任何.Rout.fail
文件。