r - R 在 Azure Pipeline 中找不到环境变量
问题描述
我正在尝试将基于 Travis 的测试转换为 Azure Pipelines,但我遇到了 R 似乎没有获取环境变量的问题。
这是yaml:
trigger:
- master
variables:
- group: GH
- name: R_LIBS_USER
value: '$(Agent.BuildDirectory)/R/library'
- name: containerImage
value: rocker/rstudio:latest
pool:
vmImage: 'ubuntu-latest'
container: rocker/rstudio:latest
steps:
- script: |
echo 'options(repos = "https://cloud.r-project.org")' > ~/.Rprofile
mkdir -p ${R_LIBS_USER}
displayName: 'Setup R library directory'
- bash: |
Rscript -e "install.packages(c('remotes', 'rcmdcheck'))" <-- problem here
Rscript -e "remotes::install_deps(dependencies=TRUE)"
displayName: 'Installing package dependencies'
- bash: |
Rscript -e "rcmdcheck::rcmdcheck(args = '--no-manual', error_on = 'error', check_dir = 'check')"
displayName: 'Checking package'
问题出bash
在我安装 remotes 和 rcmdcheck 包的步骤中,然后运行install_deps
. 由于某种原因,R 看不到 R_LIBS_USER 变量,它应该扩展为类似/__w/1/R/library
. 因此,它尝试安装到站点范围的位置/usr/local/lib/R/site-library
,但由于该目录不是用户可写的,因此失败。
这里发生了什么事?
解决方案
无论出于何种原因,R 只是看不到环境变量R_LIBS_USER
。最终对我有用的是编辑~/.Rprofile
配置文件以包含用户库目录:
steps:
- script: |
echo 'options(repos = "https://cloud.r-project.org")' > ~/.Rprofile
echo ".libPaths(c('$R_LIBS_USER', .libPaths()))" >> ~/.Rprofile
mkdir -p $(R_LIBS_USER)
displayName: 'Setup R library directory'
现在我只需要弄清楚如何避免在每次运行时重新安装几兆字节的依赖项......
推荐阅读
- github - 如何隐藏一些代码部分并在机器中完整运行
- c++ - MySQL 连接器/C++ 8 X 插件已禁用
- docker - 我在实践中对 docker 卷使用的困惑
- css - 包含内容的 1200px 媒体查询;背景颜色保持 100% 宽度
- r - for 循环中的错误 - 尝试在 integerOneIndex 中选择少于一个元素
- android - 如何在构造函数中传递参数(使用 Hilt 作为 DI)
- r - 选择组取决于 dplyr 中两列中的值
- javascript - Highcharts dataLabels 允许重叠不起作用
- sql-server - 聚集键在 SQL Server 中使用非聚集索引上升到树
- rselenium - 如何在 rsDriver 中使用旧版 chrome