Install R packages from requirements.txt file
Asked Answered
S

3

5

Is there a functionality like requirements.txt in Python, where you can store a list of packages used into a file, and whenever other people want to run your programs and need to install the dependencies, they can just do pip install -r requirements.txt.

I think, this helps a lot when deploying R script into production. If there is no such functionality, how do I replicate it?

Sherilyn answered 5/2, 2019 at 12:9 Comment(0)
S
5

Create a requirements file with any delimiter between packages and its version version. For eg.

data.table 1.11.4
DBI 1.0.0
curl 3.2

And then install it by parsing the file:

#!/usr/bin/bash
while IFS=" " read -r package version; 
do 
  Rscript -e "devtools::install_version('"$package"', version='"$version"')"; 
done < "requirements.txt"
Sherilyn answered 5/2, 2019 at 12:19 Comment(0)
N
3

You can use packrat with your project. link

Namhoi answered 25/4, 2019 at 4:27 Comment(0)
C
0

Better late then never.

There is also renv (https://github.com/rstudio/renv) which to my understanding is similar to packrat (https://github.com/rstudio/packrat). The differences between both are highligted at https://rstudio.github.io/renv/articles/packrat.html.

See the getting started guide for a good overview https://rstudio.github.io/renv/articles/renv.html.

There is also this related post Virtual environment in R?.

Cholinesterase answered 12/2 at 6:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.