Problems with manually setting R library paths

Crossposted at stackoverflow with little activity

What are the limitations of manually setting R library paths? Even when I can verify that my library paths point where I want them to, I still can't load packages.

I use conda as my package manager. With conda activated, I have the following:

(base) balter@chse4:~$ which R
~/micromamba/bin/R
(base) balter@chse4:~$ R --version
R version 4.2.3 (2023-03-15) -- "Shortstop Beagle"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: x86_64-conda-linux-gnu (64-bit)
(base) balter@chse4:~$ Rscript -e "Sys.getenv()" | grep LIB
R_LIBS_SITE             /home/users/balter/micromamba/lib/R/site-library
R_LIBS_USER             /home/users/balter/R/x86_64-conda-linux-gnu-library/4.2

If I deactivate conda, I have:

balter@chse4:~$ which R
/usr/local/bin/R
balter@chse4:~$ R --version
R version 4.2.2 (2022-10-31) -- "Innocent and Trusting"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
balter@chse4:~$ Rscript -e "Sys.getenv()" | grep LIB
setting .libPaths()...
LD_LIBRARY_PATH         /usr/local/R/4.2.2/lib64/R/lib:/usr/local/lib64:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.362.b08-1.el7_9.x86_64/jre/lib/amd64/server
R_LIBS_SITE
R_LIBS_USER             ~/R/x86_64-pc-linux-gnu-library/4.2

I have a file "Rprofile" no dot that looks like this:

balter@chse4:~$ cat Rprofile
Sys.setenv("LD_LIBRARY_PATH"="/home/users/balter/micromamba/lib")
Sys.setenv(R_DOC_DIR="/home/users/balter/micromamba/lib/R/doc")
Sys.setenv(R_INCLUDE_DIR="/home/users/balter/micromamba/lib/R/include")
Sys.setenv(R_LIBS_SITE="/home/users/balter/micromamba/lib/R/site-library")
Sys.setenv(R_LIBS_USER="/home/users/balter/micromamba/lib/R/libraries")
Sys.setenv(R_SHARE_DIR="/home/users/balter/micromamba/lib/R/share")
#Sys.setenv(RSTUDIO_WHICH_R="/home/users/balter/micromamba/bin/R")

.libPaths(c("/home/users/balter/micromamba/lib/R/library"))
.Library = "/home/users/balter/micromamba/lib/R/library"
.Library.site = "/home/users/balter/micromamba/lib/R/library"

I can source it within R, or move it to ".Rprofile" and launch R. But then I get errors loading libraries:

balter@chse4:~$ mv Rprofile .Rprofile
balter@chse4:~$ R

R version 4.2.2 (2022-10-31) -- "Innocent and Trusting"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

setting .libPaths()...
> .libPaths()
[1] "/home/users/balter/micromamba/lib/R/library"
[2] "/usr/local/R/4.2.2/lib64/R/library"
> library(tidyverse)
Error: package or namespace load failed for ‘tidyverse’:
 .onAttach failed in attachNamespace() for 'tidyverse', details:
  call: NULL
  error: package or namespace load failed for ‘tidyr’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/home/users/balter/micromamba/lib/R/library/dplyr/libs/dplyr.so':
  /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /home/users/balter/micromamba/lib/R/library/dplyr/libs/dplyr.so)
In addition: Warning message:
package ‘tibble’ was built under R version 4.2.3

Note

@Mikael -- I do get the same behavior using an ".Renviron." And, the way I use conda is to avoid problems with package compatibility. If I launch R when conda is activated I don't have any library problems, as shown in the outputs. The problem is when I launch system R but then try to use my conda libraries. The reason I'm trying to solve this is because of needing to work on a system where all I get is the system R terminal.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.