首页 > 解决方案 > 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,但由于该目录不是用户可写的,因此失败。

这里发生了什么事?

标签: razure-pipelines

解决方案


无论出于何种原因,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'

现在我只需要弄清楚如何避免在每次运行时重新安装几兆字节的依赖项......


推荐阅读