3

Related questions:

I have two homemade packages, A and B. B depends on A for some functions and has A in its DESCRIPTION file like this:

Depends: A

I have unit tests written using testthat. Loading B normally works fine, and running the tests manually (running code as a chunk) works fine. However, trying to use automated tests with devtools::test() fails with:

>devtools::test()
Loading B
Error in (function (dep_name, dep_ver = NA, dep_compare = NA)  : 
  Dependency package A not available.

I can't figure out how to begin debugging this as it runs in its own environment etc., so I can't even print anything. I suspect a .libPaths() issue, but can't confirm.

I don't know how to minimally reproduce the problem, and I cannot share the code because it is proprietary.

traceback() call:

> traceback()
6: stop("Dependency package ", dep_name, " not available.")
5: (function (dep_name, dep_ver = NA, dep_compare = NA) 
   {
       if (!requireNamespace(dep_name, quietly = TRUE)) {
           stop("Dependency package ", dep_name, " not available.")
       }
       if (xor(is.na(dep_ver), is.na(dep_compare))) {
           stop("dep_ver and dep_compare must be both NA or both non-NA")
       }
       else if (!is.na(dep_ver) && !is.na(dep_compare)) {
           compare <- match.fun(dep_compare)
           if (!compare(as.numeric_version(getNamespaceVersion(dep_name)), 
               as.numeric_version(dep_ver))) {
               warning("Need ", dep_name, " ", dep_compare, " ", 
                   dep_ver, " but loaded version is ", getNamespaceVersion(dep_name))
           }
       }
       return(TRUE)
   })(dots[[1L]][[5L]], dots[[2L]][[5L]], dots[[3L]][[5L]])
4: mapply(check_dep_version, deps$name, deps$version, deps$compare)
3: load_depends(pkg)
2: load_all(pkg, quiet = TRUE)
1: devtools::test()

sessionInfo():

> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Linux Mint 18.2

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.17                          bindr_0.1.1                           xml2_1.2.0                           
 [4] magrittr_1.5                          roxygen2_6.0.1                        devtools_1.13.6                      
 [7] tidyselect_0.2.4                      R6_2.2.2                              rlang_0.2.1                          
[10] stringr_1.3.1                         plyr_1.8.4                            dplyr_0.7.6                          
[13] tools_3.4.4                           B_1.0                                 withr_2.1.2                          
[16] commonmark_1.5                        digest_0.6.15                         assertthat_0.2.0                     
[19] tibble_1.4.2                          bindrcpp_0.2.2                        purrr_0.2.5                          
[22] testthat_2.0.0                        memoise_1.1.0                         glue_1.3.0                           
[25] stringi_1.2.3                         compiler_3.4.4                        pillar_1.2.3                         
[28] pkgconfig_2.0.1            
CoderGuy123
  • 6,219
  • 5
  • 59
  • 89

1 Answers1

1

It's possible to debug the situation using debugonce() on the devtools::test() function. This allows interactive debugging of the testing environment.

A call to installed.packages() revealed no issues, i.e. packages A and B were installed in the correct path.

Using debugonce(), I traced from devtools::test() to devtools:::load_depends() to devtools:::check_dep_version() to requireNamespace() which failed with the following error:

Loading required namespace: A
Failed with error:  ‘object 'mutate' not found whilst loading namespace 'A'’

So apparently, some kind of hidden namespace error involving a mutate() method. Problem is that the quiet=TRUE to requireNamespace() is on, and not alterable, so the error message does not get to the user, sending them down the wrong path.

Thus the answer turned out to be similar to a previous question I had answered before, just didn't realize the connection.

CoderGuy123
  • 6,219
  • 5
  • 59
  • 89