pak icon indicating copy to clipboard operation
pak copied to clipboard

Add `pkg_upgrade()`

Open gaborcsardi opened this issue 3 years ago • 7 comments

gaborcsardi avatar Apr 12 '21 09:04 gaborcsardi

Should there be a helper to upgrade all installed packages, equivalent to upgrade.packages()? Or maybe a lib_upgrade() to upgrade all the packages in a library?

jimhester avatar Apr 12 '21 12:04 jimhester

Should there be a helper to upgrade all installed packages, equivalent to upgrade.packages()? Or maybe a lib_upgrade() to upgrade all the packages in a library?

There will be a lib_upgrade() (see #168). But that is harder to implement in a useful way, because of the possible conflicts.

gaborcsardi avatar Apr 12 '21 12:04 gaborcsardi

I'd like to cheer on this pull request, and second the suggestion that there be a helper function to upgrade all packages. For someone who is not deep into the internals of pak it is not very clear whether using update.packages() would mess with all the benefits of pak (such as caching and dependency resolution), or even break things. It would really ease adoption to be able to switch completely, rather than using a mixture of both (assuming one wants to keep up to date with package development in general).

torfason avatar Feb 08 '22 13:02 torfason

would mess with all the benefits of pak (such as caching and dependency resolution), or even break things.

No, it will not break anything.

gaborcsardi avatar Feb 08 '22 13:02 gaborcsardi

Awesome, thanks for the quick reply. Great that it won't break anything, but I am assuming that it will not give all the benefits either, such as keeping the downloaded packages to prevent redownloading on a second install (such as for a check).

So I put together a quick and dirty shim to query old packages on the fly and then install the most recent version with pak:

update.packages <- function(...) {
  cat("Using old.packages() and pak() to update packages ...\n")
  d.outdated <- old.packages() |> tibble::as_tibble()
  if (nrow(d.outdated)>0) {
    pak::pak(d.outdated$Package)
  } else {
    cat("No outdated packages found.\n")
  }
}

I realize that this is by no means the same as having a real pkg_upgrade() but thought of it as a helpful standin in the meantime.

In particular, this does not pick up outdated packages on GitHub and such, but it does add a freshly installed package to pak's cache, and on a quick test, seems to work well. Of course, not everyone might like the shadowing of the native update.packages(), but anyone interested in this approach could easily rename the function to something else.

torfason avatar Feb 09 '22 16:02 torfason

Indeed, such function could be really useful. For now, I am using a one-line command with VSCode keybinding.

if (length(pkgs <- setdiff(rownames(old.packages()), "pak")) > 0) pak::pkg_install(pkgs)

mcanouil avatar Feb 26 '22 18:02 mcanouil

Yay for this FR—I assume it's the same as what I was coming to request, which is an equivalent to remotes::update_packages().

batpigandme avatar Jan 27 '23 14:01 batpigandme