如何在 R 中安装项目依赖项?

How to install project dependencies in R?

在工作时,我收到了一个闪亮的旧应用程序包。那里有一个 manifest.json 文件。来自 python,该文件看起来可以重建原始依赖项。问题是,如何在我当前的设置中安装它?我想要相当于 poetry installpip install -r requirements.txt

感谢评论,我制定了自己的解决方案,效果很好。

首先用 python 脚本创建一个 requirements.txt

"""
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)

然后使用此 bash 脚本安装所有旧依赖项

while IFS=" " read -r package version; 
do
   Rscript -e "devtools::install_version('"$package"', version='"$version"')"; 
done < "requirements.txt"