我正在使用testthat
包为我的R包编写测试。我按照http://r-pkgs.had.co.nz/tests.html的说明(我相信)。我用了
devtools::use_testthat()
设置测试骨架。我在tests/testthat
中创建了一个测试文件,文件名以test
开头。当我在RStudio中运行devtools::test()
或Ctrl + Shift + T时,测试成功运行,但是当我运行R CMD check
或Ctrl + Shift + E时,testthat
无法找到我的包。我收到了错误
> library(testthat)
>
> test_check("foo")
Loading required package: foo
Error in loadNamespace(name) : there is no package called 'foo'
Calls: test_check ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
In addition: Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called 'foo'
Execution halted
我通过在R_LIBS_SITE
文件中设置.Renviron
来修改我的库路径。我怀疑在运行R CMD check
时没有阅读,但我认为它不应该有所作为。
当我从RStudio控制台运行devtools::check()
时,它成功完成(包括测试),但运行Check in RStudio失败。
我向testthat.R
添加了一些调试以打印出.libPaths()
和其他位:
> library(testthat)
> .libPaths()
[1] "C:/Users/timk/AppData/Local/Temp/Rtmp841w0b/RLIBS_1790551706"
[2] "C:/Program Files/R/R-3.2.2/library"
> list.files(.libPaths()[1])
[1] "KernSmooth" "MASS" "Matrix" "boot" "class"
[6] "cluster" "crayon" "digest" "foo" "foreign"
[11] "lattice" "magrittr" "memoise" "mgcv" "nlme"
[16] "nnet" "praise" "rpart" "spatial" "stringi"
[21] "stringr" "survival" "testthat"
> list.files(file.path(.libPaths()[1], "foo"))
character(0)
> list.files(file.path(.libPaths()[1], "testthat"))
[1] "CITATION" "DESCRIPTION" "INDEX" "LICENSE" "MD5"
[6] "Meta" "NAMESPACE" "R" "help" "html"
[11] "libs"
您可以看到包目录是在临时库中创建的,但包是空的。将其与testthat
的文件列表进行比较。
我还尝试下载另一个使用testthat
(anonymizer)的软件包并收到同样的错误。
sessionInfo()
:
R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)
locale:
[1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252 LC_MONETARY=English_Australia.1252
[4] LC_NUMERIC=C LC_TIME=English_Australia.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] foo_0.1 testthat_0.11.0
loaded via a namespace (and not attached):
[1] magrittr_1.5 tools_3.2.2 roxygen2_5.0.0 Rcpp_0.12.1 crayon_1.3.1 memoise_0.2.1 stringi_1.0-1
[8] stringr_1.0.0 digest_0.6.8 devtools_1.9.1
答案 0 :(得分:0)
尝试在testthat
的{{1}}字段中添加Suggests:
。 R CMD CHECK只会在检查期间将该文件中提到的包放在范围内。
答案 1 :(得分:0)