miniCRAN – developing internal CRAN Repositories

[This article was first published on Mango Solutions, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

by Steph Locke

Today, I needed to work on a package that had numerous dependencies on internal packages and ones from CRAN. To be able to handle dependencies in the installation process, I needed something like CRAN so that install.packages() woul work correctly. We have an internal CRAN but I wanted to make one specific to this set of packages. Our early guidance, produced by Greg back in 2014 used a number of custom functions and manual folder structure creation. It worked but it required effort. Since then Revolution Analytics have developed miniCRAN, which was designed to make developing internal CRAN repositories a breeze.

It’s been really helpful for developing an internal repository for working on this project so I wanted to show others how easy it is too. In fact, my entire minimum reproducible example is just nine steps!

For this to be reproducible, I’ll be using the V8 package as my “internal” package and I’ll also mimic having one of it’s dependencies as a local .tar.gz file also.

  1. Install miniCRAN
# Set the repo for use throughout
cran <- ""

# Install
  install.packages("miniCRAN", repos = cran)
  1. Mimic having local R packages

# Config variables
tempdir <- tempdir()
pkg <- "V8"
pkgs <- c(pkg, "curl")

# Doesn't use miniCRAN::addPackage as it'd get all the deps
utils::download.packages(pkgs, tempdir, repos= cran)
  1. Make a CRAN structure
mCRAN <- "myminiCRAN"
# Use NULL to create an empty structure
miniCRAN::makeRepo(NULL, mCRAN
                   , repos = cran, type="source")
  1. Move my R packages to my miniCRAN
file.copy(list.files(tempdir,pattern = "*.tar.gz"
                     , full.names = TRUE)
          , file.path(mCRAN, "src", "contrib"))
  1. Update the miniCRAN index
  1. Get the file directory URI for correct referencing
uriCRAN <- paste0("file:///"
                , file.path(getwd(), mCRAN))
  1. Identify all the dependencies for a package [Only need this step to get all dependencies into miniCRAN from CRAN]
deps <- miniCRAN::pkgDep(pkg
                         , repos = uriCRAN
                         , suggests = FALSE)
# Exclude locally available packages
deps <- setdiff(deps, pkgs)
  1. Get all available dependencies from CRAN [Only need this step to get all dependencies into miniCRAN]
miniCRAN::addPackage(deps, mCRAN
                     , repos = cran
                     , writePACKAGES = TRUE
                     # Deps already captured
                     , deps = FALSE)
  1. Install the internal package
install.packages(pkg, repos = uriCRAN
                 , type="source")

I hope this has helped show you a simple workflow for building your own internal CRAN. The code is available as a gist for download.

To leave a comment for the author, please follow the link and comment on their blog: Mango Solutions. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)