- Notifications
You must be signed in to change notification settings - Fork89
Packrat is a dependency management system for R
rstudio/packrat
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Packrat has been soft-deprecated and is now superseded byrenv.
While we will continue maintaining Packrat, all new development will focus onrenv. If you're interested in switching torenv, you can userenv::migrate() to migrate a project from Packrat torenv.
Packrat is a dependency management system for R.
Use packrat to make your R projects more:
- Isolated: Installing a new or updated package for one project won't breakyour other projects, and vice versa. That's because packrat gives eachproject 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 thepackages 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 yougo.
See theproject page for more information,or join the discussion in thePosit Community forums.
Read thereleasenotes to learn what'snew in Packrat.
Start by installing Packrat:
install.packages("packrat")Then, start a new R session at the base directory of your project and type:
packrat::init()This will install Packrat, set up a private library to be used for thisproject, and then place you inpackrat mode. While in packrat mode, calls tofunctions likeinstall.packages andremove.packages will modify theprivate project library, rather than the user library.
When you want to manage the state of your private library, you can use thePackrat functions:
packrat::snapshot(): Save the current state of your library.packrat::restore(): Restore the library state saved in the most recentsnapshot.packrat::clean(): Remove unused packages from your library.
Share a Packrat project withbundle andunbundle:
packrat::bundle(): Bundle a packrat project, for easy sharing.packrat::unbundle(): Unbundle a packrat project, generating a projectdirectory with libraries restored from the most recent snapshot.
Navigate projects and set/get options with:
packrat::on(),packrat::off(): Toggle packrat mode on and off, fornavigating between projects within a single R session.packrat::get_opts,packrat::set_opts: Get/set project-specific settings.
Manage ad-hoc local repositories (note that these are a separate entity fromCRAN-like repositories):
packrat::set_opts(local.repos = ...)can be used to specifylocalrepositories; that is, directories containing (unzipped) package sources.packrat::install_local()installs packages available in a localrepository.
For example, suppose I have the (unzipped) package sources fordigest locatedwithin the folder~/git/R/digest/. To install this package, you can use:
packrat::set_opts(local.repos = "~/git/R")packrat::install_local("digest")There are also utility functions for using and managing packages in theexternal / user library, and can be useful for leveraging packages in the userlibrary that you might not want as project-specific dependencies, e.g.devtools,knitr,roxygen2:
packrat::extlib(): Load an external package.packrat::with_extlib(): With an external package, evaluate an expression.The external package is loaded only for the duration of the evaluatedexpression, but note that there may be other side effects associated withthe package's.onLoad,.onAttachand.onUnloadcalls that we may notbe able to fully control.
Packrat supports a set of common analytic workflows:
As-you-go: usepackrat::init()to initialize packrat with your project,and use it to manage your project library while you develop your analysis.As you install and remove packages, you can usepackrat::snapshot()andpackrat::restore()to maintain the R packages in your project. Forcollaboration, you can either use your favourite version control system, orusepackrat::bundle()to generate a bundled version of your project thatcollaborators can use withpackrat::unbundle().When-you're-done: take an existing or complete analysis (preferablycollected within one directory), and callpackrat::init()to immediatelyobtain R package sources for all packages used in your project, and snapshotthat state so it can hence be preserved across time.
Please view theset-upguide here for a simplewalkthrough in how you might set up your own, local, custom CRAN repository.
About
Packrat is a dependency management system for R
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.