Packrat

View the Project on GitHub rstudio/packrat

Packrat is a dependency management system for R.

R package dependencies can be frustrating. Have you ever had to use trial-and-error to figure out what R packages you need to install to make someone else’s code work–and then been left with those packages globally installed forever, because now you’re not sure whether you need them? Have you ever updated a package to get code in one of your projects to work, only to find that the updated package makes code in another project stop working?

We built packrat to solve these problems. Use packrat to make your R projects more:

Basic concepts

If you’re like the vast majority of R users, when you start working on a new R project you create a new directory for all of your R scripts and data files.

Packrat enhances your project directory by storing your package dependencies inside it, rather than relying on your personal R library that is shared across all of your other R sessions. We call this directory your private package library (or just private library). When you start an R session in a packrat project directory, R will only look for packages in your private library; and anytime you install or remove a package, those changes will be made to your private library.

Unfortunately, private libraries don’t travel well; like all R libraries, their contents are compiled for your specific machine architecture, operating system, and R version. Packrat lets you snapshot the state of your private library, which saves to your project directory whatever information packrat needs to be able to recreate that same private library on another machine. The process of installing packages to a private library from a snapshot is called restoring.

Installing packrat

Packrat is now available on CRAN, so you can install it with:

> install.packages("packrat")

If you like to live on the bleeding edge, you can also install the development version of Packrat with:

> install.packages("devtools")
> devtools::install_github("rstudio/packrat")

You’ll also need to make sure your machine is able to build packages from source. See Package Development Prerequisites for the tools needed for your operating system.

Next steps

Need help?

Drop by packrat-discuss and let us know if you have any questions or comments.