我正在使用该testthat包为我的R包编写测试.我已按照http://r-pkgs.had.co.nz/tests.html上的说明进行操作(我相信).我用了
devtools::use_testthat()
Run Code Online (Sandbox Code Playgroud)
设置测试骨架.我已经创建了一个测试文件,tests/testthat文件名以test.当我devtools::test()在RStudio中运行或按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
Run Code Online (Sandbox Code Playgroud)
我通过R_LIBS_SITE在我的.Renviron文件中设置来修改我的库路径.我怀疑这在跑步时没有被阅读R CMD check,但我认为它不应该有所作为.
当我devtools::check()从RStudio控制台运行时,它成功完成(包括测试),但运行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"
Run Code Online (Sandbox Code Playgroud)
您可以看到包目录是在临时库中创建的,但包是空的.将其与文件列表进行比较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
Run Code Online (Sandbox Code Playgroud)