r-lib / pkgdepends

R Package Dependency Resolution
https://r-lib.github.io/pkgdepends/
Other
102 stars 30 forks source link

Libraries that depends each other will fails to solve #357

Closed latot closed 7 months ago

latot commented 7 months ago

Hi, I was trying to install packages with pak::pkg_install, then I notice some packages failed to install.

This happens when we have two packages, A and B, and A depends on B, and B depends on A.

I think we all know R is not the best way to organize, conceptualize code, so there is some cases with some systems we can get things like that.

There is the argument "Split and create a new library", but there is several problems on that.

The actual error is:

Error:       
! error in pak subprocess
Caused by error in `select_next_task(state)`:
! Cannot select new package installation task.
ℹ 2 packages still waiting to install: rtestB and rtestA.
ℹ This is an internal error in pkgdepends, please report an issue at <https://github.com/r-lib/pkgdepends/issues>.
Type .Last.error to see the more details.

Well, even with this there is still some concern about it, no idea if some packages with mutual dependence need to one be installed first, but while this is only on R code there should be no problem.

Thx!

gaborcsardi commented 7 months ago

You cannot have circular dependencies in R packages, there is no way to install them. There is also no way to load these packages, if you were to managed to install them using some hack.

This is not a limitation of pak, it is the limitation of the packaging system.

latot commented 7 months ago

If you have this case, and the code is pure R, you can choose any package to install ignoring the other dependence, I have installed packages like this with devtools::install("something", dependencies = FALSE).

I would like a more robust solution for complex projects, but is not easy without break the organization and abstracts.

gaborcsardi commented 7 months ago

No, that does not work. More precisely, it only works if the dependencies are already installed, or if you are installing a binary package, which is just an untar/unzip.

You cannot install a source package without its dependencies, even if you specify dependencies = FALSE:

❯ usethis::create_package("foobar123")
✔ Creating 'foobar123/'
✔ Setting active project to '/private/tmp/foobar123'
✔ Creating 'R/'
✔ Writing 'DESCRIPTION'
[...]
✔ Writing 'NAMESPACE'

❯ desc::desc_set_dep("foobar124")
[...]

❯ desc::desc_get_deps()
     type   package version
1 Imports foobar124       *
❯ install.packages(".", repos = NULL, type = "source", dependencies = FALSE)
Installing package into ‘/Users/gaborcsardi/Library/R/arm64/4.3/library’
(as ‘lib’ is unspecified)
ERROR: dependency ‘foobar124’ is not available for package ‘foobar123’
* removing ‘/Users/gaborcsardi/Library/R/arm64/4.3/library/foobar123’
Warning message:
In install.packages(".", repos = NULL, type = "source", dependencies = FALSE) :
  installation of package ‘.’ had non-zero exit status
latot commented 7 months ago

yes, we can force the dep to be installed, then install the other one.... how complex organize in R, originally the lib I wrote... both belongs to the same one, but how I can organize the functions I needed to split it in two, but them the common functions causes this..!! and there is even more libs!

gaborcsardi commented 7 months ago

yes, we can force the dep to be installed, then install the other one...

You cannot do that if they both depend on the other.

gaborcsardi commented 7 months ago

Since we cannot do much about this, I am going to close this issue.