`local_install_deps` can't solve `<=` or `==` (or `@`) versions of DESCRIPTION packages that are not the latest
I'm trying to use pak to share dependencies in a project, but if a different version is installed pak can install a different version (through pkg_install), but can't install it with local_install_deps.
Example: DESCRIPTION:
Package: teste
Title: Teste
Version: 1.0
Depends:
R (>= 4.3.0)
Imports:
cowsay (== 0.8.2)
> library(pak)
> cache_clean()
> pkg_install("[email protected]")
✔ Loading metadata database ... done
→ Will install 1 package.
→ Will download 1 CRAN package (402.58 kB).
+ cowsay 0.9.0 [dl] (402.58 kB)
ℹ Getting 1 pkg (402.58 kB)
✔ Got cowsay 0.9.0 (i386+x86_64-w64-mingw32) (402.79 kB)
✔ Downloaded 1 package (402.79 kB) in 855ms
✔ Installed cowsay 0.9.0 (75ms)
✔ 1 pkg + 3 deps: kept 3, added 1, dld 1 (402.79 kB)[4.6s]
> local_install_deps()
Error:
! error in pak subprocess
Caused by error:
! Could not solve package dependencies:
* deps::C:/Users/Plancha/Desktop/erro_do_pak: Can't install dependency cowsay (== 0.8.2)
Type .Last.error to see the more details.
> pkg_install("[email protected]")
→ Will update 1 package.
→ Will download 1 package with unknown size.
+ cowsay 0.9.0 → 0.8.2 [bld][dl]
? Do you want to continue (Y/n) Y
ℹ Getting 1 pkg with unknown size
✔ Got cowsay 0.8.2 (source) (576.88 kB)
✔ Downloaded 1 package (576.88 kB) in 156ms
ℹ Building cowsay 0.8.2
✔ Built cowsay 0.8.2 (1.3s)
✔ Installed cowsay 0.8.2 (79ms)
✔ 1 pkg + 3 deps: kept 3, upd 1, dld 1 (576.88 kB) [13.6s]
> cowsay::say()
--------------
Hello world!
--------------
\
\
\
|\___/|
==) ^Y^ (==
\ ^ /
)=*=(
/ \
| |
/| | | |\
\| | |_|/\
jgs //_// ___/
\_)
> local_install_deps()
✔ Loading metadata database ... done
→ The package (0 B) is cached.
ℹ No downloads are needed
✔ 4 deps: kept 3 [4.7s]
> .Last.error
Registered S3 methods overwritten by 'callr':
method from
format.callr_status_error
print.callr_status_error
<callr_error/rlib_error_3_0/rlib_error/error>
Error:
! error in pak subprocess
Caused by error:
! Could not solve package dependencies:
* deps::C:/Users/Plancha/Desktop/erro_do_pak: Can't install dependency cowsay (== 0.8.2)
---
Backtrace:
1. pak::pak()
2. pak::local_install_dev_deps(...)
3. pak:::remote(function(...) { …
4. err$throw(res$error)
---
Subprocess backtrace:
1. base::withCallingHandlers(cli_message = function(msg) { …
2. get("local_install_dev_deps_make_plan", asNamespace("pak"))(...)
3. prop$stop_for_solution_error()
4. private$plan$stop_for_solve_error()
5. pkgdepends:::pkgplan_stop_for_solve_error(self, private)
6. base::throw(new_error("Could not solve package dependencies:\n", msg, …
7. | base::signalCondition(cond)
8. global (function (e) …
> pak_sitrep()
* pak version:
- 0.7.0
* Version information:
- pak platform: x86_64-w64-mingw32 (current: x86_64-w64-mingw32, compatible)
- pak repository: - (local install?)
* Optional packages installed:
- pillar
* Library path:
- C:/Users/Plancha/AppData/Local/R/win-library/4.3
- C:/Program Files/R/R-4.3.2/library
* pak is installed at C:/Users/Plancha/AppData/Local/R/win-library/4.3/pak.
* Dependency versions:
- callr 3.7.3
- cli 3.6.1
- crayon 1.5.2
- curl 5.1.0
- desc 1.4.2
- distro 0.1.0
- filelock 1.0.2
- glue 1.6.2
- jsonlite 1.8.7
- lpSolve 5.6.19
- parsedate 1.3.1
- pkgbuild 1.4.2
- pkgcache 2.2.0.1
- pkgdepends 0.7.0
- pkgsearch 3.1.2
- prettyunits 1.2.0
- processx 3.8.2
- ps 1.7.5
- R6 2.5.1
- rappdirs 0.3.3
- rprojroot 2.0.4
- zip 2.3.0
* Dependencies can be loaded
Big things but that's mostly because I wanted to include everything and pak is quite verbose, here's all the command I ran
library(pak)
cache_clean()
pkg_install("[email protected]") # installs
cowsay::say() # runs
local_install_deps() # error
pkg_install("[email protected]") # installs
local_install_deps() # runs fine
pak_sitrep()
.Last.error # the error from local_install_deps
CRAN package metadata only contains the latest versions of packages, so if you have a <= or == version requirement, that only works in practice if you also allow the latest version in the CRAN(-like) repository.
This said, we could treat pkg (== ver) as pkg@ver and then == could work.
Oh yeah that's true, I didn't even notice that local_install_deps won't install even if another version isn't installed. I'll update the title
This feature would be useful in cases where you're not actually trying to build a package, but rather collect dependencies for a set of R scripts (or notebooks, shiny app, etc.) and want to be able to specify maximum versions of some packages, without having to commit to a single specific version of every package (as pak::lockfile_create(), packrat, or renv requires).
Or if you are developing a package, but one that you're not planning on submitting to CRAN. You may generally want to be able to pin maximum dependencies for all of the standard reasons one might want to do so, accepting the cost that pak will be an implicit requirement to install your package.