Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.