Learn R Programming

renv

Overview

The renv package[^1] helps you create reproducible environments for your R projects. Use renv to make your R projects more isolated, portable and reproducible.

  • Isolated: Installing a new or updated package for one project won’t break your other projects, and vice versa. That’s because renv gives each project its own private library.
  • Portable: Easily transport your projects from one computer to another, even across different platforms. renv makes it easy to install the packages your project depends on.
  • Reproducible: renv records the exact package versions you depend on, and ensures those exact versions are the ones that get installed wherever you go.

Installation

Install the latest version of renv from CRAN with:

install.packages("renv")

Workflow

Use renv::init() to initialize renv in a new or existing project. This will set up a project library, containing all the packages you’re currently using. The packages (and all the metadata needed to reinstall them) are recorded into a lockfile, renv.lock, and a .Rprofile ensures that the library is used every time you open that project.

As you continue to work on your project, you will install and upgrade packages, either using install.packages() and update.packages or renv::install() and renv::update(). After you’ve confirmed your code works as expected, use renv::snapshot() to record the packages and their sources in the lockfile.

Later, if you need to share your code with someone else or run your code on new machine, your collaborator (or you) can call renv::restore() to reinstall the specific package versions recorded in the lockfile.

Learning more

If this is your first time using renv, we strongly recommend starting with the Introduction to renv vignette: this will help you understand the most important verbs and nouns of renv.

If you have a question about renv, please first check the FAQ to see whether your question has already been addressed. If it hasn’t, please feel free to ask on the Posit Forum.

If you believe you’ve found a bug in renv, please file a bug (and, if possible, a reproducible example) at https://github.com/rstudio/renv/issues.

[^1]: Pronounced “R” “env”

Copy Link

Version

Install

install.packages('renv')

Monthly Downloads

213,208

Version

1.0.7

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

April 11th, 2024

Functions in renv (1.0.7)

purge

Purge packages from the cache
paths

Path for storing global state
snapshot

Record current state of the project library in the lockfile
lockfiles

Lockfiles
rehash

Re-hash packages in the renv cache
settings

Project settings
modify

Modify a Lockfile
history

View and revert to a historical lockfile
remote

Resolve a Remote
rebuild

Rebuild the packages in your project library
migrate

Migrate a project from packrat to renv
renv_lockfile_from_manifest

Generate renv.lock from an RStudio Connect manifest.json
imbue

Imbue an renv Installation
refresh

Refresh the local cache of available packages
scaffold

Generate project infrastructure
record

Update package records in a lockfile
project

Retrieve the active project
sandbox

The default library sandbox
repair

Repair a project
vendor

Vendor renv in an R package
restore

Restore project library from a lockfile
run

Run a script
use_python

Use python
upgrade

Upgrade renv
remove

Remove packages
renv-package

Project-local Environments for R
update

Update packages
status

Report inconsistencies between lockfile, library, and dependencies
activate

Activate or deactivate a project
diagnostics

Print a diagnostics report
autoload

Auto-load the active project
config

User-level settings
embed

Capture and re-use dependencies within a .R or .Rmd
checkout

Checkout a repository
dependencies

Find R package dependencies in a project
consent

Consent to usage of renv
clean

Clean a project
install

Install packages
init

Use renv in a project
isolate

Isolate a project
load

Load a project
lockfile-api

Programmatically Create and Modify a Lockfile
equip

Install required system libraries
hydrate

Copy packages from user libraries to a project library
graph

Generate a Package Dependency Graph