I will be able to confirm whether this works when people try it on Wednesday. I followed along with instructions here to install packages in a Windows binary onto a USB stick, so that people can install them from source rather than from the internet on site.
First, list the package dependencies for our workshop
#' 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)
# Remove base dependencies, these are installed with R and not published on CRAN
basePackages <- c("base","compiler","datasets","graphics","grDevices","grid",
"methods","parallel","splines","stats","stats4","tcltk","tools","utils")
packageNames <- setdiff(packageNames, basePackages)
packageNames
}
pkgs <- getDependencies(c('dplyr','ggplot2','readr','lubridate',
'leaflet','htmlwidgets','scales', 'targets'))
Then, install them on a USB stick
First, Windows
# Download the packages to the working directory.
# Package names and filenames are returned in a matrix.
setwd("D:/my_usb/win_pkgs/")
winPkgInfo <- download.packages(pkgs = pkgs, destdir = getwd(), type = "win.binary")
# Save just the package file names (basename() strips off the full paths leaving just the filename)
write.csv(file = "win_pkgs.csv", basename(winPkgInfo[, 2]), row.names = FALSE)
Then, Mac
# Download the packages to the working directory.
# Package names and filenames are returned in a matrix.
setwd("D:/my_usb/mac_pkgs/")
macPkgInfo <- download.packages(pkgs = pkgs, destdir = getwd(), type = "mac.binary")
# Save just the package file names (basename() strips off the full paths leaving just the filename)
write.csv(file = "mac_pkgs.csv", basename(macPkgInfo[, 2]), row.names = FALSE)
Then, I put the folders and the following R scripts on each USB:
win_pkg_install.R
# Set working directory to the location of the package files
setwd("D:/my_usb/win_pkgs/")
# Read the package filenames and install
pkgFilenames <- read.csv("win_pkgs.csv", stringsAsFactors = FALSE)[, 1]
install.packages(pkgFilenames, repos = NULL, type = "win.binary")
mac_pkg_install.R
# Set working directory to the location of the package files
setwd("D:/my_usb/mac_pkgs/")
# Read the package filenames and install
pkgFilenames <- read.csv("mac_pkgs.csv", stringsAsFactors = FALSE)[, 1]
install.packages(pkgFilenames, repos = NULL, type = "mac.binary")
I will be able to confirm whether this works when people try it on Wednesday. I followed along with instructions here to install packages in a Windows binary onto a USB stick, so that people can install them from source rather than from the internet on site.
First, list the package dependencies for our workshop
Then, install them on a USB stick
First, Windows
Then, Mac
Then, I put the folders and the following R scripts on each USB:
win_pkg_install.Rmac_pkg_install.R