r-lib / devtools

Tools to make an R developer's life easier
https://devtools.r-lib.org
Other
2.39k stars 760 forks source link

devtools::test() can`t load installed packages for my tests #2414

Closed BekyP closed 2 years ago

BekyP commented 2 years ago

Hi,

I am testing my R package on github actions with devtools::test() but for some reason devtools can`t load packages for tests. Packages are installed in global library directory - same directory where devtools is installed. R code:

  remotes::install_github("r-lib/devtools@v2.4.2", upgrade = "never")

  install.packages("RPostgres")

  print(Sys.getenv("R_LIBS"))

  list.files(path = "/usr/local/lib/R/site-library")

  library("devtools")

  sessioninfo::session_info()

  devtools::test(pkg = "./package-dir", reporter = testthat::JunitReporter$new(file = "junit_result.xml"), stop_on_failure = FALSE)

Error after running tests (related to RPostgres package):

Error in `abort_for_missing_packages()`:
! Dependency package(s) 'RPostgres' not available.
Backtrace:
    ▆
 1. └─devtools::test(...)
 2.   └─devtools::load_all(pkg$path)
 3.     └─pkgload::load_all(...)
 4.       └─pkgload:::load_imports(path)
 5.         └─pkgload:::abort_for_missing_packages(res, imports$package)
 6.           └─rlang::abort(...)
Warning message:
In (function (dep_name, dep_ver = "*")  :
  Dependency package 'RPostgres' not available.
Execution halted

session info:

─ Session info ───────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 4.0.5 (2021-03-31)
 os       Ubuntu 20.04.3 LTS          
 system   x86_64, linux-gnu           
 ui       X11                         
 language (EN)                        
 collate  en_US.UTF-8                 
 ctype    en_US.UTF-8                 
 tz       Etc/UTC                     
 date     2022-03-11                  

─ Packages ───────────────────────────────────────────────────────────────────
 package     * version date       lib source                         
 brio          1.1.3   2021-11-30 [1] RSPM (R 4.0.5)                 
 cachem        1.0.5   2021-05-15 [1] RSPM (R 4.0.4)                 
 callr         3.7.0   2021-04-20 [1] RSPM (R 4.0.4)                 
 cli           3.1.1   2022-01-20 [1] RSPM (R 4.0.5)                 
 crayon        1.4.2   2021-10-29 [1] RSPM (R 4.0.5)                 
 curl          4.3.2   2021-06-23 [1] RSPM (R 4.0.5)                 
 desc          1.4.0   2021-09-28 [1] RSPM (R 4.0.5)                 
 devtools    * 2.4.2   2022-03-11 [1] Github (r-lib/devtools@6bcaf88)
 ellipsis      0.3.2   2021-04-29 [1] RSPM (R 4.0.5)                 
 fastmap       1.1.0   2021-01-25 [1] RSPM (R 4.0.3)                 
 fs            1.5.0   2020-07-31 [1] RSPM (R 4.0.3)                 
 glue          1.6.1   2022-01-22 [1] RSPM (R 4.0.5)                 
 lifecycle     1.0.1   2021-09-24 [1] RSPM (R 4.0.5)                 
 magrittr      2.0.2   2022-01-26 [1] RSPM (R 4.0.5)                 
 memoise       2.0.0   2021-01-26 [1] RSPM (R 4.0.3)                 
 pkgbuild      1.2.0   2020-12-15 [1] RSPM (R 4.0.3)                 
 pkgload       1.2.4   2021-11-30 [1] RSPM (R 4.0.5)                 
 prettyunits   1.1.1   2020-01-24 [1] RSPM (R 4.0.3)                 
 processx      3.5.2   2021-04-30 [1] RSPM (R 4.0.4)                 
 ps            1.6.0   2021-02-28 [1] RSPM (R 4.0.3)                 
 purrr         0.3.4   2020-04-17 [1] RSPM (R 4.0.5)                 
 R6            2.5.1   2021-08-19 [1] RSPM (R 4.0.5)                 
 remotes     * 2.3.0   2021-04-01 [1] RSPM (R 4.0.4)                 
 rlang         1.0.1   2022-02-03 [1] RSPM (R 4.0.5)                 
 rprojroot     2.0.2   2020-11-15 [1] RSPM (R 4.0.3)                 
 sessioninfo   1.1.1   [201](...)8-11-05 [1] RSPM (R 4.0.3)                 
 testthat      3.1.2   [202](...)2-01-20 [1] RSPM (R 4.0.5)                 
 usethis     * 2.0.1   2021-02-10 [1] RSPM (R 4.0.3)                 
 withr         2.4.3   2021-11-30 [1] RSPM (R 4.0.5)

[1] /usr/local/lib/R/site-library
[2] /usr/local/lib/R/library

I can see that RPostgres is installed. RPostgres is also in package DESCRIPTION file under Imports. I tried to use load_package = "source" and load_package = "installed" - but I`ve got same error. I also tried newer and older devtools versions, again same error. Any suggestions or tips that I could try?

BekyP commented 2 years ago

after some detective work I found out the problem with RPostgres package wasn't in his unavailability, but in missing linux libraries for postgres -> you should update error messages that are printed, don't print generic message about dependency not available, but rather print the underlying issue that is logged via the library itself (RPostres in this case)

hadley commented 2 years ago

You likely need to look upstream in the log to figure out why RPostgres wasn't installed.