At work I received an old shiny application bundle. In there there is both a manifest.json
file. Coming from python, the file looks like it could rebuild the original dependecies. The question is, how do install it in my current setup? I would like to have the equivalent of a poetry install
or pip install -r requirements.txt
Asked
Active
Viewed 156 times
0

DaveR
- 1,696
- 18
- 24
-
1Does this answer your question? [Is there something like requirements.txt for R?](https://stackoverflow.com/questions/38928326/is-there-something-like-requirements-txt-for-r), See also https://stackoverflow.com/questions/54534153/install-r-packages-from-requirements-txt-file, and https://github.com/rstudio/packrat. The manifest is very likely coming from `pakrat`. Please refer to their document how to install from the manifest. – lz100 Apr 13 '22 at 22:33
1 Answers
1
Thanks to the comment, I made my own solution that worked well.
First create a requirements.txt
with a python script.
"""
Read a manifest.json and output a requirements.txt file
"""
import json
file = 'manifest.json'
out = 'requirements.txt'
with open(file) as json_file:
data = json.load(json_file)
with open(out, 'w') as f:
for pkg_name in data['packages'].keys():
pkg_version = data['packages'][pkg_name]['description']['Version']
res = f'{pkg_name} {pkg_version} \n'
f.write(res)
Then install all the old dependencies with this bash
script
while IFS=" " read -r package version;
do
Rscript -e "devtools::install_version('"$package"', version='"$version"')";
done < "requirements.txt"

DaveR
- 1,696
- 18
- 24