2

I am trying to work with an R package that includes Rcpp + OpenMP in a conda environment in macOS. I read the conda environment documentation; however, I could not fix the problem I have in the following reproducible example. Most of the documentation is based on addressing OpenMP issues (clang+llvm) on macOS. I was wondering if there are any resources or documentation for the conda environment. These steps work on a Linux system (with conda) and macOS (without conda) without any problem.

Here is the reproducible example:

In a macOS:

Step 1: Create a conda environment and install R:

conda create -n env r-essentials r-base

Step 2: activate the environment

conda activate env

Step 3: install rstudio

conda install -c r rstudio

Step 4: install some required packages

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

Step 5: Run rstudio

Step 6: Inside rstudio

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

I get the following error:

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);
 ~~^

I think I need to set some environmental variables; however, I could not find out which variables I should export. Do you have any idea?

Naeem Khoshnevis
  • 2,001
  • 4
  • 18
  • 30

1 Answers1

5

Works for me, with some adjustments that I regard as better practice:

  • don't use RStudio from Conda - it is an abandoned project; see alternatives
  • only use conda-forge channel - mixing channels can have dynamic library issues
  • use a YAML for more reliable specification of requirements
  • explicitly declare R version (r-base)
  • include everything in the declared Imports (except what is included as dependencies of other packages)
  • conda-forge::r-cli>=3 builds are broken, so I pin that to newest working version
  • use mamba because conda is slow

Here is a YAML for creating the environment:

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

And the steps are:

  1. Create env.

    ## 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. Run R session in env.

    conda activate causalgps
    R
    
  3. Install package.

    library(devtools)
    install_github('fasrc/CausalGPS')
    
  4. Test loading.

    library(CausalGPS) ## works
    
merv
  • 67,214
  • 13
  • 180
  • 245