我正在使用testthat
軟件包爲我的R軟件包編寫測試。我遵循http://r-pkgs.had.co.nz/tests.html(我相信)的指示。我用在運行R CMD檢查時未找到R軟件包測試
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
我在我的.Renviron
文件中設置R_LIBS_SITE
修改我的庫路徑。我懷疑這在運行R CMD check
時沒有被讀取,但我認爲它不應該有所作爲。
當我從RStudio控制檯運行devtools::check()
時,它成功完成(包括測試),但運行檢查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
幾天前我在'adegenet'的一個分支上運行檢查,並且所有地獄都輸了。在用戶環境路徑中添加'R_LIBS_USER'後,事情就會發生。你的'.libPaths()'說什麼? –
一個很好的問題。我添加了輸出以顯示'.libPaths()'和臨時庫的內容。軟件包目錄正在創建,但它是空的。 –
您是否嘗試將'R_LIB_USER'添加到用戶環境或刪除第一個(臨時)文件夾? –