Skip to content

Instantly share code, notes, and snippets.

@rvprasad
Last active October 2, 2021 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rvprasad/fbd3807ed07b07246f6f220a6037c7e1 to your computer and use it in GitHub Desktop.
Save rvprasad/fbd3807ed07b07246f6f220a6037c7e1 to your computer and use it in GitHub Desktop.
Update existing packages to new version of R
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