Search code examples
rpackagedependenciescircular-dependency

circular dependency error in R package check, yet no circular refs in Depends


I am getting a circular dependency error for my R package when running CHECK:

checking package dependencies ... ERROR
  There is circular dependency in the installation order:
    One or more packages in

then a long list of packages.

However, my Depends category in DESCRIPTION is very minimal:

Depends: methods, R (>= 3.5.0), magrittr

And all other referenced packages are in either Imports or Suggests. One package I have in Imports also lists my package in their Imports, but I did not think that would lead to a dependency issue. I don't think any of the other packages I have in DESCRIPTION list mine in theirs.

I've searched quite a bit online but found no relevant solutions. Any ideas? Thanks in advance for the advice.

Session info:

R version 4.0.5 (2021-03-31)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

loaded via a namespace (and not attached):
[1] compiler_4.0.5 tools_4.0.5    tinytex_0.31   xfun_0.28     

Solution

  • Depends and imports both require a dependency. The main difference is that imports doesn't add items to the user's search path. See here or here. You can't list a package under your "imports" that lists you under their "imports" -- that part is the same as "depends." Packages use functions from packages all the time, but the sharing is just one-way.

    One possible work-around is copying the function (with permission from the other package author) into your own package.

    Another option that I've seen used by other packages is to move shared logic to a separate helper package and then both packages can Import that helper package.

    Finally, if it's a function you don't really need you can move it to suggests and then check if that package is installed only when you need the function and can throw an error if not.