Mirror R/CRAN for internal use

The statistical analysis system R can be extended by a huge number of contributed packages which are stored in the central CRAN repository with multiple synced mirrors around the world. To access this repository from clients in a secure network, and install the packages in a local R installation may pose a security risk, require multiple complicated steps or support from the IT team. Therefore, a solution is to mirror the complete CRAN repository at a single time point (similar to the MRAN repository for MS R open) and make the downloaded repository available on a internal network attached storage (alt. local or external harddrive):

1) The CRAN repository can be downloaded as follows in a Linux environment (cf HOWTO):

$BASH> rsync -rtlzv –stats –ignore-existing –delete rsync://ftp.acc.umu.se/mirror/CRAN/ ./CRAN/

The dump of CRAN as of 2018-04-26 used about 197GB of disk storage.

I modified the rsync command since the used mirror did not support SSH, and rsync crashed multiple times, because I think the network bandwidth was higher than the USB2-writing speed of my Linux installation on my Synology NAS Drive, which I used for the download and for copying the files to an connected external USB harddrive. Therefore, I just restarted the download multiple times till it was finished. You can also limit the I/O bandwidth using the “–bwlimit” flag which may avoid such problems (see rsync manual).

Alternatively, in a MS Windows environment other clients supporting rsync may be used , e.g. DeltaCopy (untested).

2) One has to generate a package index in the local repository in R:

## Create PACKAGES and PACKAGES.gz file as package index for R version 3.4.x
$R> library(tools)
$R> write_PACKAGES(“D:/CRAN/bin/windows/contrib/3.4/”) # Note: Windows Path

3) One can also check the default library and set a user-defined R library:

## set user-defined library path
$R> .libPaths()
$R> .libPaths(c(“D:\Rlib”, .libPaths())) # Note: Windows Path

3) One can then install packages (including all dependent packages) with the following command:

## Example of installation of mlr package with multiple dependencies
$R> install.packages(“mlr”,
repos=NULL,
dependencies=TRUE,
contriburl=”file:D:/CRAN/bin/windows/contrib/3.4/”) # Note: Windows Path

Happy computing! 🙂