Goal: Understand R environments build with Conda.
Note: There is a known vulnerability with R versions less than 4.4.0.
This page uses R version 4.3.3. This page is purely for example since as of the date of creating this page there were issues using an r-base/4.4.1.
I am hoping in a few weeks/months the 4.4.x base will be stable and I’ll update the examples.
Basic R Conda Environment
General Process:
[salexan5@mblog2 ~]$ cd /project/arcc/software/conda-envs/ [salexan5@mblog2 conda-envs]$ module load miniconda3/24.3.0 [salexan5@mblog2 conda-envs]$ conda search r-base Loading channels: done # Name Version Build Channel ... r-base 4.3.3 hf0d99cb_1 conda-forge ... r-base 4.4.1 h1dca405_0 conda-forge [salexan5@mblog2 conda-envs]$ conda create -p r_4.3.3_env r-base=4.3.3 [salexan5@mblog2 conda-envs]$ conda activate /cluster/medbow/project/arcc/software/conda-envs/r_4.3.3_env (/cluster/medbow/project/arcc/software/conda-envs/r_4.3.3_env) [salexan5@mblog2 conda-envs]$ R --version R version 4.3.3 (2024-02-29) -- "Angel Food Cake" ...
Where are Packages Installed?
Lets look at the environment variables:
(/cluster/medbow/project/arcc/software/conda-envs/r_4.3.3_env) [salexan5@mblog2 conda-envs]$ R -e 'Sys.getenv(c("R_PLATFORM", "R_HOME", "R_LIBS_USER"))' R version 4.3.3 (2024-02-29) -- "Angel Food Cake" ... > Sys.getenv(c("R_PLATFORM", "R_HOME", "R_LIBS_USER")) R_PLATFORM "x86_64-conda-linux-gnu" R_HOME "/cluster/medbow/project/arcc/software/conda-envs/r_4.3.3_env/lib/R" R_LIBS_USER "/cluster/medbow/home/salexan5/R/x86_64-conda-linux-gnu-library/4.3"
Note: The platform string value is different: x86_64-conda-linux-gnu
Try Installing vctrs
Package
# Within R: > install.packages("vctrs") ... also installing the dependencies ‘cli’, ‘glue’, ‘lifecycle’, ‘rlang’ ... * DONE (vctrs)
Where was this installed?
Remember our environment variables:
R_LIBS_USER "/cluster/medbow/home/salexan5/R/x86_64-conda-linux-gnu-library/4.3" R_HOME "/cluster/medbow/project/arcc/software/conda-envs/r_4.3.3_env/lib/R"
[salexan5@mblog2 ~]$ ls /home/salexan5/R/x86_64-conda-linux-gnu-library/4.3 ls: cannot access '/home/salexan5/R/x86_64-conda-linux-gnu-library/4.3': No such file or directory [salexan5@mblog2 ~]$ ls /home/salexan5/R/ x86_64-pc-linux-gnu-library
Why is /home/salexan5/R/x86_64-conda-linux-gnu-library/4.3
missing?
I own this Conda environment, so have permission to install under: /project/arcc/software/conda-envs/r_4.3.3_env/lib/R
- lets check:
[salexan5@mblog2 ~]$ ls /project/arcc/software/conda-envs/r_4.3.3_env/lib/R/library/ base cli compiler datasets glue graphics grDevices grid lifecycle methods parallel rlang splines stats stats4 tcltk tools translations utils vctrs
The ~/R/x86_64-conda-linux-gnu-library/4.3
location is where R will additionally look for outside packages not directly part of this Conda environment.
Try Installing stringi
Package
# Within R: > install.packages("stringi") ... configure: error: in `/tmp/RtmpVm7ias/R.INSTALL2ad60710733cd2/stringi': configure: error: C++ compiler cannot create executables See `config.log' for more details ERROR: configuration failed for package ‘stringi’ * removing ‘/cluster/medbow/project/arcc/software/conda-envs/r_4.3.3_env/lib/R/library/stringi’ The downloaded source packages are in ‘/tmp/Rtmpio5YFH/downloaded_packages’ Updating HTML index of packages in '.Library' Making 'packages.html' ... done Warning message: In install.packages("stringi") : installation of package ‘stringi’ had non-zero exit status
Conda environments are not the same as the System/compute nodes - libraries and behavior can be different.
Conda Install stringi
Package: Search
(/cluster/medbow/project/arcc/software/conda-envs/r_4.3.3_env) [salexan5@mblog2 conda-envs]$ conda search stringi Loading channels: done No match found for: stringi. Search: *stringi* # Name Version Build Channel r-stringi 0.4_1 r3.1.3_0 pkgs/r ... r-stringi 1.8.4 r43hbd1cc82_0 conda-forge (/cluster/medbow/project/arcc/software/conda-envs/r_4.3.3_env) [salexan5@mblog2 conda-envs]$ conda search r-stringi Loading channels: done # Name Version Build Channel r-stringi 0.4_1 r3.1.3_0 pkgs/r ... r-stringi 1.8.4 r43hbd1cc82_0 conda-forge
Remember: Conda r packages use the naming convention: r_<package-name>
Conda Install stringi
Package
(/cluster/medbow/project/arcc/software/conda-envs/r_4.3.3_env) [salexan5@mblog2 conda-envs]$ conda install r-stringi Channels: - conda-forge - defaults Platform: linux-64 Collecting package metadata (repodata.json): done Solving environment: done ## Package Plan ## environment location: /cluster/medbow/project/arcc/software/conda-envs/r_4.3.3_env added / updated specs: - r-stringi The following NEW packages will be INSTALLED: r-stringi conda-forge/linux-64::r-stringi-1.8.4-r43hbd1cc82_0 ... Executing transaction: done
Where was this installed?
[salexan5@mblog2 ~]$ ls /project/arcc/software/conda-envs/r_4.3.3_env/lib/R/library/ base cli compiler datasets glue graphics grDevices grid lifecycle methods parallel rlang splines stats stats4 stringi tcltk tools translations utils vctrs
The Conda install of the R package is installed within the same location as the R install.packages() function.
/project/arcc/software/conda-envs/r_4.3.3_env/lib/R/library/
Anaconda: R Essentials
Although we do not recommend installing Anaconda (unless you are comfortable with how it works and modifies your home environment), it does provide an R Essentials bundle which “includes approximately 80 of the most popular scientific packages for the R programming language.“
conda install -c r r-essentials