Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a local R package repository

Tags:

r

r-package

I would like to create a local R package repository such that users in my company can install packages from it and the system admins can update the local repo periodically. Access to the CRAN mirrors is currently denied.

Is there a simple way to do this?

like image 808
harshsinghal Avatar asked May 25 '10 14:05

harshsinghal


People also ask

Can you install R packages offline?

To install these packages offline, you can download a compressed file that matches your operating system from ; copy the file to your offline machine. In some cases you'll have to download the dependencies packages as well; if this is required, it will be noted under your package link.


1 Answers

Yes, either a copy of CRAN or a repo with local packages is easy to set up. Presumably you want this for Windows so do this:

  1. Create a top-level directory on your webserver, say R/
  2. Create the usual hierarchy in there: R/bin/windows/contrib/2.11. If you need to support other (earlier) releases, simply create directories 2.10, 2.9, ... next to the 2.11 directory.
  3. Place the packages you need into the directory (say, 2.11), then change into that directory and run the following command to generate PACKAGES and PACKAGES.gz files for the repository:

    tools::write_PACKAGES(".", type="win.binary")

That is all there is to it -- now you can access the repository by pointing to the address given a command such as

update.packages(repos="http://my.local.server/R", ask=FALSE) 

which I even do in R/zzz.R for local packages so that they update themselves.

Edit some five+ years later: And the drat package now automates a lot of this, and shines particularly if you also use GitHub to serve the repository over http/https (but is useful for other or local hosting too).

like image 110
Dirk Eddelbuettel Avatar answered Sep 25 '22 01:09

Dirk Eddelbuettel