I am using the testthat
package to write tests for my R package. I have followed the instructions at http://r-pkgs.had.co.nz/tests.html (I believe). I used
devtools::use_testthat()
to set up the testing skeleton. I have created a test file in tests/testthat
and the filename begins with test
. When I run devtools::test()
or Ctrl+Shift+T in RStudio, the tests run successfully, however when I run R CMD check
or Ctrl+Shift+E, testthat
cannot find my package. I get the error
> 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
I do modify my library path by setting R_LIBS_SITE
in my .Renviron
file. I suspect that this is not being read when running R CMD check
, but I don't think that it should make a difference.
When I run devtools::check()
from the RStudio Console, it completes successfully (including tests), however running Check in RStudio fails.
I added some debugging to testthat.R
to print out .libPaths()
and other bits:
> 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"
You can see that the package directory is created in the temporary library, however the package is empty. Compare it with the file list for testthat
.
I have also tried downloading another package that uses testthat
(anonymizer) and am getting the same error.
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
Try adding testthat
in the Suggests:
field of DESCRIPTION
. R CMD CHECK will only put in scope the packages mentioned in that file during a check.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With