Last active
October 5, 2023 12:08
-
-
Save andrewmoles2/18e1a636aeadc42f503212fde1ddc6ba to your computer and use it in GitHub Desktop.
Script to aid in installing packages after R update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# script to upgrade R and re-install all (or at least most) packages | |
# Pre-upgrade: save your packages as an rds file | |
my_pkg <- pak::pkg_list() | |
# if loaded from RStudio | |
#here::here("R", "update_packages", "my_packages.rds") | |
# if loaded from finder | |
saveRDS(object = my_pkg, file = "my_packages.rds") | |
# -------------- | |
# now upgrade R - https://www.r-project.org/ | |
# -------------- | |
# after upgrade, bring back the rds file | |
my_pkg <- readRDS("my_packages.rds") | |
# first, install all the cran packages | |
inst <- my_pkg$package[my_pkg$repository == "CRAN"] | |
install.packages(inst, type = "binary", Ncpus = 6) | |
# check what is installed | |
now <- pak::pkg_list() | |
# see what is missing | |
missing <- my_pkg[!my_pkg$package %in% now$package, ] | |
# if installed from github, make name vector | |
add <- paste0(missing$remoteusername, "/", missing$remoterepo) | |
add <- add[!add %in% "NA/NA"] | |
# now install github | |
pak::pak(add) | |
# see if there is anything left | |
final <- pak::pkg_list() | |
final_missing <- my_pkg[!my_pkg$package %in% final$package, ] | |
paste(final_missing$package) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment