How to update all packages for a new R version quickly and easily?

Viewed 7256

Suppose I have R version 3.x.x installed, and I upgrade to version 4.x.x, is there any quick/easy way to install all the new versions of the libraries I had installed?

Please assume all the packages are on CRAN

2 Answers

Don't know if this is quick and easy, but I think the pacman package can be useful.

  1. Under the previous version, use pacman::p_lib() to return a vector of your installed packages, and save them onto disk use saveRDS().

For instance,

mypks <- pacman::p_lib()
saveRDS(mypks, "~/mypks.rds")
  1. Update R.

  2. Import the vector from step 1 using readRDS() and run install.packages() with the object.

For instance,

mypks <- readRDS("~/mypks.rds")
install.packages(mypks)

Step 1

Run this in the previous R installation:

# install.packages("pacman")
library(pacman)
dput(pacman::p_lib())

Copy the output to clipboard.

Step 2

Open your new R version, paste the output from the previous step in place of ***paste output here***:

vector_of_packages <- ***paste output here***
install.packages(vector_of_packages)

Notes:

  • This is just a lazier way of doing what @Phil suggests.
Related