Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 15 Next »

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_LIBS", "R_LIBS_SITE"))'
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"
  R_LIBS      ""
  R_LIBS_SITE "/cluster/medbow/project/arcc/software/conda-envs/r_4.3.3_env/lib/R/site-library"

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?

Check .libPaths():

(/cluster/medbow/project/arcc/software/conda-envs/r_4.3.3_env) [salexan5@mblog2 ~]$ R
R version 4.3.3 (2024-02-29) -- "Angel Food Cake"
...
> .libPaths()
[1] "/cluster/medbow/project/arcc/software/conda-envs/r_4.3.3_env/lib/R/library"

Since I own this Conda environment, I 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

But What about the R_LIBS_USER Environment Variable?

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

Since this folder is missing, it is not being picked up and used by the .libPaths() command.


Can I Create this Folder?

If you manually create this folder then .libPaths() does pick it up.

(/cluster/medbow/project/arcc/software/conda-envs/r_4.3.3_env) [salexan5@mblog2 R]$ mkdir -p x86_64-conda-linux-gnu-library/4.3
(/cluster/medbow/project/arcc/software/conda-envs/r_4.3.3_env) [salexan5@mblog2 R]$ R
R version 4.3.3 (2024-02-29) -- "Angel Food Cake"
...
> .libPaths()
[1] "/cluster/medbow/home/salexan5/R/x86_64-conda-linux-gnu-library/4.3"
[2] "/cluster/medbow/project/arcc/software/conda-envs/r_4.3.3_env/lib/R/library"

Using the install.packages() command within R will now look/install packages into this folder that could be shared across multiple Conda environments using this version of R.

image-20240729-234708.png

Should I Create this Folder?

Question: Should you manually create the ~/R/x86_64-conda-linux-gnu-library/X.Y/ folder?

First, we would suggest that unless you are confident in self-managing your Conda/R environments then do not.

If this is not in your .libPaths(), then it will force all R package installs to be contained under the Conda environment.

If this path IS in your .libPaths(), across multiple conda environments, then all the environments will install into and look/share this folder.

You can run into dependency/version issues if you want to use version X of a package in one Conda environment, but version Y in another. You can only have one version in this folder.

We have observed that some times this folder have been automatically created.

Best thing is to always check and set the .libPaths() to you necessary needs.


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

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

 

 

  • No labels