While working in a conda environment, I have been observing an unexpected behavior with R>=4.1.3. Namely, in terminal I can launch R and load GDAL-based libraries
R version 4.1.3 (2022-03-10) -- "One Push-Up"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-conda-linux-gnu (64-bit)
... STANDARD R MESSAGE ...
> library(sf)
Linking to GEOS 3.11.1, GDAL 3.6.2, PROJ 9.1.0; sf_use_s2() is TRUE
but in RStudio I get the error below
R version 4.1.3 (2022-03-10) -- "One Push-Up"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-conda-linux-gnu (64-bit)
... STANDARD R MESSAGE ...
> library(sf)
Error: package or namespace load failed for ‘sf’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/home/ivan/miniconda3/envs/r41_dev/lib/R/library/sf/libs/sf.so':
/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /home/ivan/miniconda3/envs/r41_dev/lib/R/library/sf/libs/../../../../libgdal.so.32)
Even though the behavior in terminal suggested that the package libstdc++
was installed, I have reinstalled it from the Gnome repo. The package is definitely installed on my machine.
apt list --installed | grep libstdc++
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
libstdc++-8-dev/focal,now 8.4.0-3ubuntu2 amd64 [installed,automatic]
libstdc++-9-dev/focal-updates,focal-security,focal-security,now 9.4.0-1ubuntu1~20.04.1 amd64 [installed,automatic]
libstdc++6/focal,now 11.1.0-1ubuntu1~20.04 amd64 [installed]
libstdc++6/focal,now 11.1.0-1ubuntu1~20.04 i386 [installed,automatic]
The Rstudio version is
RStudio 2022.07.2+576 "Spotted Wakerobin" Release (e7373ef832b49b2a9b88162cfe7eac5f22c40b34, 2022-09-06) for Ubuntu Bionic
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.12.8 Chrome/69.0.3497.128 Safari/537.36
And here the session info
> sessionInfo()
R version 4.1.3 (2022-03-10)
Platform: x86_64-conda-linux-gnu (64-bit)
Running under: Ubuntu 20.04.5 LTS
Matrix products: default
BLAS/LAPACK: /home/ivan/miniconda3/envs/r41_dev/lib/libopenblasp-r0.3.21.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=de_DE.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=de_DE.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=de_DE.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.1.3 magrittr_2.0.3 class_7.3-21 DBI_1.1.3 tools_4.1.3 units_0.8-1
[7] proxy_0.4-27 Rcpp_1.0.10 KernSmooth_2.23-20 grid_4.1.3 e1071_1.7-13 classInt_0.4-8
I have been using conda environments with RStudio for a while and I have come across multiple challenges but I don't seem capable to come around this one.
Can anyone help me understand how come RStudio cannot access this package while R can access it from terminal?
As as side note, the problem does not occur with R=4.0.5 and, to the best of my knowledge, did not occur with R=4.1 either. I certainly have update apt multiple times, but I cannot recall any major update to my system.
EDIT TO ADDRESS THE POINTS RAISED BY @merv IN COMMENTS
I have created several environments with different R versions in the attempt to frame and solve this problem, without success.
I've now followed these steps:
conda -V
, returns conda 22.11.1
conda create -n r41_test -c conda-forge r-base=4.1.3 r-sf -y
conda activate r41_test
1 save the conda list
output to file and share it through this linklibrary(sf)
, the library loads without issuesq()
and type n
to avoid workspace image to be savedrstudio
(from the activated environment)library(sf)
from the R console in RStudio, the library fails loading with the same error reported above.While running this test, I have noticed something I had not noticed before: when the conda environment at step 2, the following message was printed, but the environment was successfully create. I could also activate it, launch R from terminal, and load the library despite the SafetyError
.
Downloading and Extracting Packages
Preparing transaction: done
Verifying transaction: |
SafetyError: The package for r-base located at /home/ivan/miniconda3/pkgs/r-base-4.1.3-h2f963a2_5
appears to be corrupted. The path 'lib/R/doc/html/packages.html'
has an incorrect size.
reported size: 3061 bytes
actual size: 55120 bytes
done
Previous my post, I have tried this procedure also on another laptop running Ubuntu 20.04. I barely use that machine so it may serve as an 'independent control'. I am not sure whether the SafetyError
was thrown also there, but RStudio failed to load the package also on that machine.
I think it is because rstudio installed via deb packages does not use the libstdc++.so
from the conda environment.
Try with:
conda activate my-env
export LD_LIBRARY_PATH=/path/to/envs/my-env/lib/
rstudio