Drat: Drat R Archive Template


What cute people say when they are pissed off

"Oh Drat, i lost my wallet"

Urban Dictionary


The R package ecosystem is one of the cornerstones of the success seen by R. As of this writing, over 6200 are on CRAN, several hundred more at BioConductor and at OmegaHat.

Support for multiple repositories is built deeply into R; mostly via the (default) package utils. The update.packages function (along with several others from the utils package) can used for these three default repositories as well as many others with ease. But it seemed that support for simple creation and use of local repositories was however missing.

Drat tries to help here.

TL;DR Real Fast

See the vignettes

for a really quick topical introduction to drat either package authors (ie publishing packages) or package users (ie installing or updating packages).

Also see the drat page on GitHub. More documentation follows below as well.

Drat Use Case 1: GitHub

Adding a Repository

GitHub has emerged as the dominant repository for many participants and issues. The range spans anything from the White House over to Google and of course includes countless open source endeavours---among them many R projects. Winston mirrors the R sources. Gabor mirrors all of CRAN, but more importantly many CRAN authors now develop their code via a GitHub repo.

And many point their users to devtools::install_github(). Which works for one-time installation but as we pointed out above, R shines via its ability for incremental updates via repositories.

Drat can help by leveraging GitHub further. Suppose someones wanted to make my Drat repository available for their machine(s).

After a simple first


all that is needed is


or equally drat:::add("eddelbuettel") to use an unexported short-hand function.

We can use the fact that with a given username (here: eddelbuettel) and the file-system structure known to drat and suggested to drat, the repository metadata will be found by the next update.packages().

Inserting a Package into a Repository

Creating and updating a package repository is equally easy. Drat takes the view that releases matter. While access to individual commits is something which git makes easy, we reckon that most users will want actual package sources most of the time.

Any user can create a repository drat; the easiest way may be to clone mine. And by enabling a gh-pages branch (see e.g. this tutorial for a refresher, or these articles), the repository gets web-accessible content.

Bingo! This is all that Drat needs. And adding a tarball, say drat_0.0.3.tar.gz which corresponds to the very first initial package of drat, is as easy as


as the default git repository locally is inferred (via ~/git/drat/) but can be overriden as both a local default (via options()) or directly on the command-line as shown in the second example using the alternative unexported short-hand function:

drat:::insert("drat_0.0.1.tar.gz", "/opt/myWork/git")

Actual adding, commiting and pushing can be triggered with another optional argument.

Drat Use Case 2: Local Server

Sometimes R package work cannot go to GitHub. What gets done at work is probably a common example; not-quite-ready for the world do see code may be another. You may still want to share with co-workers, you advisor or students or simply access it conveniently from your other machines.

Drat supports this mode too.

Adding a Repository

One adds a local repository via something like

addRepo("localRepo", "http://localServer.localNet/work/R/drat")

where the first argument is used (as before) for naming the value in variable stored as options("repos") but instead of deriving a GitHub-based URL we rely on an explicitly given one.

Inserting a Package into a Repository

Similar to the GitHub use case, one can do

insertPackage("drat_0.0.1.tar.gz", "/nfs/localRepo/R/drat")

Note that the target directory must be accessible for file copy, directory change and writes (as the package index is updated).


To use drat repositories in your R sessions, either interactively or maybe via a startup file such as ~/.Rprofile (see `help(Startup)``1 for more), do


where one or more GitHub accounts can be listed. Adding local repositories can be added as well.


The package is hosted in this GitHub repository. After some initial delay, it is now also available from CRAN via install.packages("drat") and via its CRAN package page.


The package is still relatively young but has seen considerable use, and a number of forks. Contributions are always welcome.


GPL (>= 2) just like R itself.


Dirk Eddelbuettel

Initially created: Sun Feb 01 13:21:53 CDT 2015
Last modified: Wed May 20 09:00:54 CDT 2015