0

I find that when I try to load some packages in a conda environement, when using rstudio (but not when I'm using R directly), I get an error message about a missing Rcpp.so file.

I activate my conda environment (which is running R version 4.1), open RStudio (which I installed independently of the conda environment), I have no problem installing say the glmnet package with

`install.packages("glmnet")

however

library(glmnet) returns

Loading required package: Matrix
Error: package or namespace load failed for ‘glmnet’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/home/jacob/miniconda3/envs/r41/lib/R/library/Rcpp/libs/Rcpp.so':
  /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by /home/jacob/miniconda3/envs/r41/lib/R/library/Rcpp/libs/Rcpp.so)

However, if I close out of rstudio and run R from the terminal

> library(glmnet)
Loading required package: Matrix
Loaded glmnet 4.1-3

I thought maybe installing rstudio through conda might help, but that lead me to this issue, where I was advised not to use conda rstudio.

I sure would like to use conda, because it seems to be the easist way to install multiple versions of R on my computer, and I'd like to use rstudio for the usual reasons. Any advice for getting these to play together? BTW, running rstudio not in the conda environment, I can load glmnet just fine.

This thread looks like a similar problem in Jupyter. However the suggestions to not use conda don't help me, and the one to try conda install r-rcpp has no effect.

My conda environment has the following installed:

# packages in environment at /home/jacob/miniconda3/envs/r41:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       1_gnu    conda-forge
_r-mutex                  1.0.1               anacondar_1    conda-forge
binutils_impl_linux-64    2.36.1               h193b22a_2    conda-forge
binutils_linux-64         2.36                 hf3e587d_6    conda-forge
bwidget                   1.9.14               ha770c72_1    conda-forge
bzip2                     1.0.8                h7f98852_4    conda-forge
c-ares                    1.18.1               h7f98852_0    conda-forge
ca-certificates           2021.10.8            ha878542_0    conda-forge
cairo                     1.16.0            ha00ac49_1009    conda-forge
curl                      7.82.0               h2283fc2_0    conda-forge
expat                     2.4.7                h27087fc_0    conda-forge
font-ttf-dejavu-sans-mono 2.37                 hab24e00_0    conda-forge
font-ttf-inconsolata      3.000                h77eed37_0    conda-forge
font-ttf-source-code-pro  2.038                h77eed37_0    conda-forge
font-ttf-ubuntu           0.83                 hab24e00_0    conda-forge
fontconfig                2.13.96              h8e229c2_1    conda-forge
fonts-conda-ecosystem     1                             0    conda-forge
fonts-conda-forge         1                             0    conda-forge
freetype                  2.10.4               h0708190_1    conda-forge
fribidi                   1.0.10               h36c2ea0_0    conda-forge
gcc_impl_linux-64         9.4.0               h03d3576_13    conda-forge
gcc_linux-64              9.4.0                h391b98a_6    conda-forge
gettext                   0.19.8.1          h73d1719_1008    conda-forge
gfortran_impl_linux-64    9.4.0               h0003116_13    conda-forge
gfortran_linux-64         9.4.0                hf0ab688_6    conda-forge
graphite2                 1.3.13            h58526e2_1001    conda-forge
gsl                       2.7                  he838d99_0    conda-forge
gxx_impl_linux-64         9.4.0               h03d3576_13    conda-forge
gxx_linux-64              9.4.0                h0316aca_6    conda-forge
harfbuzz                  3.4.0                hb4a5f5f_0    conda-forge
icu                       69.1                 h9c3ff4c_0    conda-forge
jbig                      2.1               h7f98852_2003    conda-forge
jpeg                      9e                   h7f98852_0    conda-forge
kernel-headers_linux-64   2.6.32              he073ed8_15    conda-forge
keyutils                  1.6.1                h166bdaf_0    conda-forge
krb5                      1.19.2               h08a2579_4    conda-forge
ld_impl_linux-64          2.36.1               hea4e1c9_2    conda-forge
lerc                      3.0                  h9c3ff4c_0    conda-forge
libblas                   3.9.0           13_linux64_openblas    conda-forge
libcblas                  3.9.0           13_linux64_openblas    conda-forge
libcurl                   7.82.0               h2283fc2_0    conda-forge
libdeflate                1.10                 h7f98852_0    conda-forge
libedit                   3.1.20191231         he28a2e2_2    conda-forge
libev                     4.33                 h516909a_1    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libgcc-devel_linux-64     9.4.0               hd854feb_13    conda-forge
libgcc-ng                 11.2.0              h1d223b6_13    conda-forge
libgfortran-ng            11.2.0              h69a702a_13    conda-forge
libgfortran5              11.2.0              h5c6108e_13    conda-forge
libglib                   2.70.2               h174f98d_4    conda-forge
libgomp                   11.2.0              h1d223b6_13    conda-forge
libiconv                  1.16                 h516909a_0    conda-forge
liblapack                 3.9.0           13_linux64_openblas    conda-forge
libnghttp2                1.47.0               he49606f_0    conda-forge
libopenblas               0.3.18          pthreads_h8fe5266_0    conda-forge
libpng                    1.6.37               h21135ba_2    conda-forge
libsanitizer              9.4.0               h79bfe98_13    conda-forge
libssh2                   1.10.0               ha35d2d1_2    conda-forge
libstdcxx-devel_linux-64  9.4.0               hd854feb_13    conda-forge
libstdcxx-ng              11.2.0              he4da1e4_13    conda-forge
libtiff                   4.3.0                h542a066_3    conda-forge
libuuid                   2.32.1            h7f98852_1000    conda-forge
libwebp-base              1.2.2                h7f98852_1    conda-forge
libxcb                    1.13              h7f98852_1004    conda-forge
libxml2                   2.9.12               h885dcf4_1    conda-forge
libzlib                   1.2.11            h36c2ea0_1013    conda-forge
lz4-c                     1.9.3                h9c3ff4c_1    conda-forge
make                      4.3                  hd18ef5c_1    conda-forge
ncurses                   6.2                  h58526e2_4    conda-forge
openssl                   3.0.0                h7f98852_2    conda-forge
pango                     1.50.5               h4dcc4a0_0    conda-forge
pcre                      8.45                 h9c3ff4c_0    conda-forge
pcre2                     10.37                h032f7d1_0    conda-forge
pixman                    0.40.0               h36c2ea0_0    conda-forge
pthread-stubs             0.4               h36c2ea0_1001    conda-forge
r-base                    4.1.2                h2553ce4_1    conda-forge
r-curl                    4.3.2             r41hcfec24a_0    conda-forge
readline                  8.1                  h46c0cb4_0    conda-forge
sed                       4.8                  he412f7d_0    conda-forge
sysroot_linux-64          2.12                he073ed8_15    conda-forge
tk                        8.6.12               h27826a3_0    conda-forge
tktable                   2.10                 hb7b940f_3    conda-forge
xorg-kbproto              1.0.7             h7f98852_1002    conda-forge
xorg-libice               1.0.10               h7f98852_0    conda-forge
xorg-libsm                1.2.3             hd9c2040_1000    conda-forge
xorg-libx11               1.7.2                h7f98852_0    conda-forge
xorg-libxau               1.0.9                h7f98852_0    conda-forge
xorg-libxdmcp             1.1.3                h7f98852_0    conda-forge
xorg-libxext              1.3.4                h7f98852_1    conda-forge
xorg-libxrender           0.9.10            h7f98852_1003    conda-forge
xorg-libxt                1.2.1                h7f98852_2    conda-forge
xorg-renderproto          0.11.1            h7f98852_1002    conda-forge
xorg-xextproto            7.3.0             h7f98852_1002    conda-forge
xorg-xproto               7.0.31            h7f98852_1007    conda-forge
xz                        5.2.5                h516909a_1    conda-forge
zlib                      1.2.11            h36c2ea0_1013    conda-forge
zstd                      1.5.2                ha95c52a_0    conda-forge
ohnoplus
  • 1,205
  • 1
  • 17
  • 29
  • Wait do you need multiple versions of R or Rstudio? Multiple versions of r definitely don't need conda to work well, and there are way better ways to keep track of packages like renv – Bruno Mar 22 '22 at 02:28
  • You can just install however many r versions you would like and switch them on rstudio itself – Bruno Mar 22 '22 at 02:29
  • 3
    Personally, I do use Conda to manage all my R environments, but the golden rule is: don't use `install.packages()`. Everything you need should be available through Conda Forge with an `r-` prefix (try `conda install -c conda-forge r-glmnet`). And if it isn't, many of us Conda Forge maintainers are more than happy to help add anything missing. – merv Mar 22 '22 at 03:20
  • @merv I understand the principle of using conda to install r-packages. I find that in practice, I often have trouble finding packages in conda forge, and so I've been using renv for package management. In this case though , `conda install -c conda-forge r-glmnet` does seem to solve the problem. Thanks. – ohnoplus Mar 22 '22 at 14:26
  • @Bruno Multiple version of R. I have yet to find a convenient way of running and switching between multiple R versions on Linux. I get that it can be done with a bunch of source installs and then switching the path variable every time I want a different version. And maybe the later can be automated, but it seems like a project. – ohnoplus Mar 22 '22 at 14:27
  • But as an example, r packages that only exist in github, and a lot of stuff in bioconductor often don't play nicely with conda, in my experience. – ohnoplus Mar 22 '22 at 14:32
  • In principle I can do the r-skeleton thing and build them on my system and then upload to my anaconda repository and then download. However, (1) this takes a bunch of time for each package and (2) I've never gotten it to work. – ohnoplus Mar 22 '22 at 14:40
  • Kinda tangential, but what Bioconductor packages have been an issue (I'm also in CompBio and contribute to Bioconda)? Have you filed issues on [the `bioconda-recipes` repository](https://github.com/bioconda/bioconda-recipes/issues)? – merv Mar 22 '22 at 15:26
  • @merv sorry don't remember and its been a while since I had problems with bioconda. Those may no longer be an issue. – ohnoplus Mar 22 '22 at 16:36
  • @Bruno Installing a second version of R from source turned out to be not so bad. I just created an alias `alias RS41='RSTUDIO_WHICH_R=/opt/R/4.1.3/bin/R'` so that I can export the relevant rstudio library to my terminal window before I launch rstudio. – ohnoplus Mar 22 '22 at 16:38
  • However @Bruno, in linux I don't think I can switch versions on rstudio itself. – ohnoplus Mar 22 '22 at 16:39
  • Interesting, I haven't used bare linux in a long while, I guess long live wsl... – Bruno Mar 22 '22 at 16:40
  • Maybe set up a env variable per project with the correct R Version? in the ~/.profile usually export RSTUDIO_WHICH_R=/opt/R/4.1.3/bin/R, It probably will overwrite your defaults... I don't know how you would do it per project – Bruno Mar 22 '22 at 16:40
  • I would love to do that. Can you direct me to any resources that explain how that might work. Turns out I was able to load the new R version once and then never again. – ohnoplus Mar 22 '22 at 16:42
  • https://support.rstudio.com/hc/en-us/articles/200486138-Changing-R-versions-for-the-RStudio-Desktop-IDE – Bruno Mar 22 '22 at 16:45
  • And that was because in the bashrc it should be `alias RS41='export RSTUDIO_WHICH_R=/opt/R/4.1.3/bin/R'` – ohnoplus Mar 22 '22 at 16:45
  • My impression is that putting `export RSTUDIO_WHICH_R=/opt/R/4.1.3/bin/R` in my .profile should make my system always use that version. I see in your earlier comment that you said you don't know how to do this per project. That might be a good topic for another post. – ohnoplus Mar 22 '22 at 16:47

1 Answers1

0

try export LD_LIBRARY_PATH=$CONDA_PREFIX/lib after activating your conda environment and before starting rstudio

Peter
  • 215
  • 2
  • 8