【问题标题】:Working with an R package under a conda environment in macOS在 macOS 的 conda 环境下使用 R 包
【发布时间】:2021-09-29 04:55:14
【问题描述】:

我正在尝试在 macOS 的 conda 环境中使用包含 Rcpp + OpenMP 的 R 包。我阅读了 conda 环境文档;但是,我无法解决以下可重现示例中的问题。大多数文档都是基于解决 macOS 上的 OpenMP 问题(clang+llvm)。我想知道 conda 环境是否有任何资源或文档。这些步骤在 Linux 系统(使用 conda)和 macOS(没有 conda)上运行没有任何问题。

这是可重现的示例:

在 macOS 中:

第 1 步:创建 conda 环境并安装 R:

conda create -n env r-essentials r-base

第 2 步:激活环境

conda activate env

第 3 步:安装 rstudio

conda install -c r rstudio

第 4 步:安装一些必需的软件包

conda install -c r r-devtools
conda install -c r r-wcorr
conda install -c r r-ranger
conda install -c conda-forge r-rcpparmadillo
conda install -c r r-testthat
conda install -c conda-forge r-superlearner
conda install -c conda-forge r-polycore
conda install -c conda forge r-logger
conda install -c anaconda llvm
conda install -c conda-forge openmp

第 5 步:运行 rstudio

第 6 步:在 rstudio 内部

library('devtools')
install_github('fasrc/CausalGPS')

我收到以下错误:

In file included from ColorSpace.cpp:1:
In file included from ./ColorSpace.h:4:
In file included from env/bin/../include/c++/v1/typeinfo:60:
In file included from env/bin/../include/c++/v1/exception:81:
In file included from env/bin/../include/c++/v1/cstdlib:85:
In file included from env/bin/../include/c++/v1/stdlib.h:100:
env/bin/../include/c++/v1/math.h:773:12: error: no member named 'labs' in the global namespace; did you mean 'abs'?
 return ::labs(__x);
     ~~^
~/env/bin/../include/c++/v1/math.h:772:39: note: 'abs' declared here
inline _LIBCPP_INLINE_VISIBILITY long abs(long __x) _NOEXCEPT {
                   ^
~/env/bin/../include/c++/v1/math.h:777:12: error: no member named 'llabs' in the global namespace
 return ::llabs(__x);
     ~~^
~/env/bin/../include/c++/v1/math.h:785:12: error: no member named 'fabsf' in the global namespace
 return ::fabsf(__lcpp_x);
     ~~^
~/env/bin/../include/c++/v1/math.h:789:12: error: no member named 'fabs' in the global namespace; did you mean 'abs'?
 return ::fabs(__lcpp_x);
     ~~^
~/env/bin/../include/c++/v1/math.h:772:39: note: 'abs' declared here
inline _LIBCPP_INLINE_VISIBILITY long abs(long __x) _NOEXCEPT {
                   ^
~/env/bin/../include/c++/v1/math.h:794:12: error: no member named 'fabsl' in the global namespace
 return ::fabsl(__lcpp_x);
 ~~^

我想我需要设置一些环境变量;但是,我找不到应该导出哪些变量。你有什么想法吗?

【问题讨论】:

    标签: r macos conda


    【解决方案1】:

    对我有用,进行一些我认为是更好的做法的调整:

    • 不要使用 Conda 的 RStudio - 这是一个废弃的项目; see alternatives
    • 仅使用 conda-forge 通道 - 混合通道可能存在动态库问题
    • 使用 YAML 获得更可靠的需求规范
    • 明确声明 R 版本 (r-base)
    • 包含the declared Imports 中的所有内容(除了作为其他包的依赖项包含的内容)
    • conda-forge::r-cli>=3 builds are broken,所以我把它固定到最新的工作版本
    • 使用mamba,因为conda 很慢

    这是一个用于创建环境的 YAML:

    causalgps-env.yaml

    name: causalgps
    channels:
      - conda-forge
    dependencies:
      - r-base=4.1
      - r-tidyverse
      - r-devtools
      - r-xgboost
      - r-superlearner
      - r-earth
      - r-ranger
      - r-gam
      - r-kernsmooth
      - r-gnm
      - r-polycor
      - r-wcorr
      - r-rlang
      - r-glue
      - r-logger
      - r-cli>=2,<3
    

    步骤如下:

    1. 创建环境。

      ## install Mamba if you don't have it
      ## conda install -n base conda-forge::mamba
      mamba env create -n causalgps -f causalgps-env.yaml
      
    2. 在环境中运行 R 会话。

      conda activate causalgps
      R
      
    3. 安装包。

      library(devtools)
      install_github('fasrc/CausalGPS')
      
    4. 测试加载。

      library(CausalGPS) ## works
      

    【讨论】:

    • 完美。非常感谢!
    • 只是想指出r-cli 构建现在已经修复,所以不需要保留约束。
    猜你喜欢
    • 2018-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-26
    • 2021-05-16
    • 2020-10-12
    • 2019-09-02
    相关资源
    最近更新 更多