Last active
April 29, 2019 12:17
-
-
Save dougmet/9f90d64520302db82ae3667314f10f59 to your computer and use it in GitHub Desktop.
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
# This is saving a task I have every now and then to download a list of packages, and | |
# their dependencies, so that I can manually copy them somewhere. | |
# Date and R version should probably be parameterised | |
options("repos" = "https://mran.microsoft.com/snapshot/2018-01-01") # modern | |
stopifnot(R.version$minor == "4.3") | |
#' Get package dependencies | |
#' | |
#' @param packs A string vector of package names | |
#' | |
#' @return A string vector with packs plus the names of any dependencies | |
getDependencies <- function(packs){ | |
dependencyNames <- unlist( | |
tools::package_dependencies(packages = packs, db = available.packages(), | |
which = c("Depends", "Imports"), | |
recursive = TRUE)) | |
packageNames <- union(packs, dependencyNames) | |
packageNames | |
} | |
# Explicit dependencies that you need | |
pkgList <- c("ggplot2", "dplyr", "tidyr", "stringr", "roxygen2", "testthat", "devtools", "assertr") | |
# Calculate dependencies | |
packages <- getDependencies(pkgList) | |
pkgInfo <- download.packages(pkgs = packages, destdir = "Packages3.4/", type = "win.binary") | |
# Save just the package file names (basename() strips off the full paths leaving just the filename) | |
write.csv(file = "pkgFilenames.csv", basename(pkgInfo[, 2]), row.names = FALSE) | |
# Installing ---------------------------------------------------------------------------------- | |
pkgsDir <- "D:/RSetup/Packages3.4" # wherever you put all those zip files | |
for (p in dir(pkgsDir, "*.zip")) { | |
pth <- file.path(root, p) | |
install.packages(pth, repos = NULL, type = "win.binary") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment