Skip to content

Instantly share code, notes, and snippets.

@stephlocke
Last active January 19, 2017 09:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save stephlocke/765692b378454b554a73 to your computer and use it in GitHub Desktop.
Save stephlocke/765692b378454b554a73 to your computer and use it in GitHub Desktop.
Getting a local CRAN that combines internal and external packages
## ------------------------------------------------------------------------
# Set the repo for use throughout
cran <- "https://cran.rstudio.org"
# Install
if(!require(miniCRAN)){
install.packages("miniCRAN", repos = cran)
}
## ------------------------------------------------------------------------
library(miniCRAN)
# Config variables
tempdir <- tempdir()
pkg <- "V8"
pkgs <- c(pkg, "curl")
# Doesn't use miniCRAN::addPackage as it'd get all the deps
dir.create(tempdir)
utils::download.packages(pkgs, tempdir, repos= cran)
## ------------------------------------------------------------------------
mCRAN <- "myminiCRAN"
dir.create(mCRAN)
# Use NULL to create an empty structure
miniCRAN::makeRepo(NULL, mCRAN
, repos = cran, type="source")
## ------------------------------------------------------------------------
file.copy(list.files(tempdir,pattern = "*.tar.gz"
, full.names = TRUE)
, file.path(mCRAN, "src", "contrib"))
## ------------------------------------------------------------------------
miniCRAN::updateRepoIndex(mCRAN)
## ------------------------------------------------------------------------
uriCRAN <- paste0("file:///"
, file.path(getwd(), mCRAN))
## ------------------------------------------------------------------------
deps <- miniCRAN::pkgDep(pkg
, repos = uriCRAN
, suggests = FALSE)
# Exclude locally available packages
deps <- setdiff(deps, pkgs)
## ------------------------------------------------------------------------
miniCRAN::addPackage(deps, mCRAN
, repos = cran
, writePACKAGES = TRUE
# Deps already captured
, deps = FALSE)
## ------------------------------------------------------------------------
install.packages(pkg, repos = uriCRAN
, type="source")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment