Last active
October 2, 2021 21:49
-
-
Save rvprasad/fbd3807ed07b07246f6f220a6037c7e1 to your computer and use it in GitHub Desktop.
Update existing packages to new version of R
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
library(gtools) | |
installed <- c() | |
update <- function(p) { | |
pd <- packageDescription(p, fields=c('Built')) | |
pd <- gsub(";.*", "", pd) | |
if (!is.na(pd) && pd != 'R 4.0.4') { # mention the target versions here | |
for (d in getDependencies(p)) { | |
update(d) | |
} | |
if (!is.element(p, installed)) { | |
install.packages(p) | |
} | |
installed <<- c(installed, p) | |
print(paste("Installed", length(installed), "packages")) | |
} | |
} | |
packages <- rownames(installed.packages()) | |
print(paste("Installing", length(packages), "packages")) | |
for (p in packages) { | |
update(p) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment