Last active
December 7, 2018 16:05
-
-
Save benmarwick/57807d786d5dd666739e9a3c1d3fac6a to your computer and use it in GitHub Desktop.
Providing CRAN packages in low- or no-bandwidth environments using miniCRAN as described in https://software-carpentry.org/blog/2015/03/teaching-in-yangon.html
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
## For the user with a new installation of R. | |
# They get a USB stick with a directory containing an .RProj file, | |
# the workshop files, and the local_CRAN directory. They open | |
# the .RProj, which sets the working directory for RStudio, and then | |
# they open this file and run it, which installs pkgs from | |
# the local_CRAN directory on the USB stick. | |
# Specify list of packages to install | |
pkgs <- c('ggplot2', 'rmarkdown', 'knitr') | |
# Set location to store source files | |
local_CRAN <- paste0(getwd(), "/local_CRAN") | |
# do installation | |
install.packages(pkgs, | |
repos = paste0("file:///", local_CRAN), | |
type = "source") | |
# make packages available to this session | |
sapply(pkgs, require, character.only = TRUE) |
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
############################################################ | |
# Prepare a local repo of packages using miniCRAN | |
# for students to install offline. The workshop leader runs | |
# this script to prepare the local_CRAN directory. This | |
# script is not provided to the students | |
# We need to have a good internet connection for these steps | |
library("miniCRAN") | |
# Specify list of packages to download | |
pkgs <- c('stringr', 'devtools', 'ggplot2', 'dplyr', 'tidyr', 'rmarkdown', 'knitr', 'reshape2', 'gdata', 'xlsx') | |
# Make list of package URLs | |
revolution <- c(CRAN="http://cran.revolutionanalytics.com") | |
pkgList <- pkgDep(pkgs, repos=revolution, type="source" ) | |
# Set location to store source files | |
local_CRAN <- paste0(getwd(), "/local_CRAN") | |
# Make repo for source and binaries, I just get source and win because I know | |
# no-one has OSX (too expensive!) | |
makeRepo(pkgList, path = local_CRAN, repos = revolution, type = "source") | |
makeRepo(pkgList, path = local_CRAN, repos = revolution, type = "win.binary") | |
# install... | |
install.packages(pkgs, | |
repos = paste0("file:///", local_CRAN), | |
type = "source") | |
# test to see if we can use them | |
sapply(pkgs, require, character.only = TRUE) | |
############################################################ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you can get away with one makeRepo command by doing type = c("source", "win.binary")