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
adegenet
and all hell broke lose. After addingR_LIBS_USER
to the user environment path, things picked up. What does your.libPaths()
say? – Ive.libPaths()
and the contents of the temporary library. The package directory is being created, but it is empty. – ColotomyR_LIB_USER
to the user environment or removing the first (temporary) folder? – IveR_LIBS_USER
andR_LIBS_SITE
but neither got passed down to the check. I think that the most odd thing is the if I calldevtools::check()
from the console it works (including running the tests), however if I use the RStudio Check Package, it doesn't. I cannot see the difference between these calls. – Colotomy