R: Packrat: Reproducible dependency management

packrat {packrat} | R Documentation

## Packrat: Reproducible dependency management

### Description

Packrat is a tool for managing the R packages your project depends on in an isolated, portable, and reproducible way.

### Details

Use packrat to make your R projects more:

- Isolated: Installing a new or updated package for one project won't break your other projects, and vice versa. That's because packrat gives each project its own private package library.

- Portable: Easily transport your projects from one computer to another, even across different platforms. Packrat makes it easy to install the packages your project depends on.

- Reproducible: Packrat records the exact package versions you depend on, and ensures those exact versions are the ones that get installed wherever you go.

Use `init` to create a new packrat project, `snapshot` to record changes to your project's library, and `restore` to recreate your library the way it was the last time you (or anyone!) took a snapshot.

Using these simple functions and sharing packrat's files lets you collaborate in a shared, consistent environment with others as your project grows and changes, and provides an easy way to share your results when you're done.

### Anatomy of a packrat project

A packrat project contains a few extra files and directories. The `init` function creates these files for you, if they don't already exist.

`packrat/lib/`

  Private package library for this project.

`packrat/src/`

  Source packages of all the dependencies that packrat has been made aware of.

`packrat/packrat.lock`

  Lists the precise package versions that were used to satisfy dependencies, including dependencies of dependencies. (This file should never be edited by hand!)

`.Rprofile`

  Directs R to use the private package library (when it is started from the project directory).

### Using packrat with version control

Packrat is designed to work hand in hand with Git, Subversion, or any other version control system. Be sure to check in the `.Rprofile`, `packrat.lock` files, and everything under `packrat/src/`. You can tell your VCS to ignore `packrat/lib/` (or feel free to check it in if you don't mind taking up some extra space in your repository).

### Author(s)

RStudio, Inc.

### Examples

    ## Not run:
    # Create a new packrat project from an existing directory of \R code
    init()

    # Install a package and take a snapshot of the new state of the library
    install.packages("TTR")
    snapshot()

    # Accidentally remove a package and restore to add it back
    remove.packages("TTR")
    restore()

    ## End(Not run)

[Package packrat version 0.4.9 Index]