Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
---
title: "Package management with `renv`"
author: "Jonas Hagenberg"
date: "17.11.2021"
output:
xaringan::moon_reader:
css: xaringan-themer.css
lib_dir: libs
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
---
```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
```
```{r xaringan-themer, include=FALSE, warning=FALSE}
library(xaringanthemer)
style_duo_accent(
primary_color = "#1a5f96",
secondary_color = "#03A696",
code_inline_background_color = "#f8f8f8"
)
```
# What is package management?
- control the versions of the packages you use
--
- make your analysis reproducible -> for your future you or a collaborator
--
- from `R`: `packrat`, from `python`: `venv`, `conda`
--
- for every project/analysis, you can use a different set of packages/versions
---
# Why `renv`?
- newest tool that is under active development by `rstudio`
--
- lightweight and easy to get started
--
- can be used to support more complicated use cases, e.g. combine containers
with a custom library on the cluster
---
# How to use it
1. install it:
```{r, eval = FALSE}
install.packages("renv")
```
--
2. create a new RStudio project
--
3. initialise `renv`:
```{r, eval = FALSE}
renv::init()
```
--
4. work normally on your project, install packages (or update them with
`renv::update()`)
--
5. when you want to save the new status of your packages, use
```{r, eval = FALSE}
renv::snapshot()
```
???
do a live presentation here: start a new project, initialise R, install a
package, use it in a script, snapshot, look at lockfile
---
# How does it work?
- `renv` uses a private package library specific for each project
--
- the packages are copied from a central `renv` package cache on your computer,
so that they don't need to be installed from CRAN every time
--
- the package versions are stored in `renv.lock` in a json format. This can be
added to version control and others can use the lockfile
--
- `renv` automatically discovers which packages are used in your projects
(by inspecting `library` calls and `library::function` syntax)
???
this means that it can also be introduced into an already existing project
---
# Caveats
- only the package & `R` versions are recorded, nothing else (e.g. no system
libraries)
--
- if you want absolute control, use container
--
- recorded package versions could not be available at a later point of time
---
# More information
Look at the official [documentation](https://rstudio.github.io/renv/articles/renv.html)