Last active
September 7, 2020 14:13
-
-
Save gadenbuie/82a2cc13aea47515914323766dd4ad56 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Step 1 ------------------------------------------------------------------ | |
# Before updating R... | |
`%>%` <- magrittr::`%>%` | |
# Thanks Chuck Powell - https://ibecav.github.io/update_libraries/ | |
package_source <- function(pkg){ | |
x <- as.character(packageDescription(pkg)$Repository) | |
if (length(x)==0) { | |
y <- as.character(packageDescription(pkg)$GithubRepo) | |
z <- as.character(packageDescription(pkg)$GithubUsername) | |
if (length(y)==0) { | |
return("Other") | |
} else { | |
return(paste0(z, "/", y)) | |
} | |
} else { | |
return(x) | |
} | |
} | |
pkgs <- | |
tibble::as_tibble(installed.packages()) %>% | |
dplyr::filter(is.na(Priority)) %>% | |
dplyr::select(Package, Version, Depends, Imports, NeedsCompilation) %>% | |
janitor::clean_names() %>% | |
dplyr::mutate(source = purrr::map_chr(package, package_source)) | |
dplyr::count(pkgs, source) | |
dplyr::filter(pkgs, source == "Other") | |
r_version <- paste(R.version[c("major", "minor")], collapse = ".") | |
r_pkgs_csv <- paste0("~/.pkgs_", r_version, ".csv") | |
readr::write_csv(pkgs, r_pkgs_csv) | |
message("Wrote installed packages to ", r_pkgs_csv) | |
# Step 2 ------------------------------------------------------------------ | |
# Download R 4.0.2 from: | |
# > https://cloud.r-project.org/bin/macosx/R-4.0.2.pkg | |
install.packages("remotes") | |
# Step 3 ------------------------------------------------------------------ | |
# restart R session and re-install packages | |
# r_pkgs_csv <- "SET TO PATH CREATED ABOVE!" | |
options(install.packages.check.source = "no") | |
pkgs <- read.csv(r_pkgs_csv) # what, no stringsAsFactor?!?! | |
# > cran packages ---- | |
cran_pkgs <- pkgs[pkgs$source == "CRAN", ] | |
cran_pkgs <- cran_pkgs[cran_pkgs$package != "tidycells", ] | |
remotes::install_cran(cran_pkgs$package, source = "binary") | |
# > github packages ---- | |
github_pkgs <- subset(pkgs, grepl("/", source)) | |
failed <- c() | |
lapply(github_pkgs$source, function(repo) { | |
tryCatch( | |
remotes::install_github(repo, upgrade = "never"), | |
error = function(e) failed <<- c(failed, repo) | |
) | |
}) | |
if (length(failed)) { | |
message("Failed to install: ", paste(failed, collapse = ", ")) | |
} | |
# > other ---- | |
# investigate "other" packages and install manually | |
other_pkgs <- subset(pkgs, source == "Other") | |
other_pkgs$package |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment