I try to use conda for as many software installations in data analysis as possible, as this will ususally guarantee that I can use up to date versions of that software.
This now includes R, and as I mostly use R through Rstudio Desktop, I checked how I can use a custom R installation with Rstudio Desktop. As described in the Rstudio docs, you just have to set the environment variable RSTUDIO_WHICH_R
to the R
binary of your wanted installation. For this environment variable to be set when launching Rstudio from Ubuntu's application launcher, you have to make the respective environment setting in the rstudio.desktop
file.
As a reminder for me, and maybe as info for others, the general setup is:
- Install Rstudio: https://www.rstudio.com/products/rstudio/download/#download
- Install (Mini-)conda: https://conda.io/miniconda.html
- Add the
conda-forge
channel that contains ar-base
and lots ofR
packages:conda config --add channels conda-forge
- Create a conda environment with a basic
R
installation:conda create -n R r-base r-tidyverse
- Find the path to the
R
installation. The following should give you something like:/path/to/miniconda3/envs/R/bin/R
:
conda activate R
whereis R
- Find the
rstudio.desktop
file:locate rstudio.desktop
. This should give something like:/usr/share/applications/rstudio.desktop
- Edit this file with
sudo
, addingenv RSTUDIO_WHICH_R=/path/to/miniconda3/envs/R/bin/R
after=
sign of theExec=
key.
If you need further R packages, search for them with conda, usually using the prefix r-
, so e.g.:
conda search r-extrafont
If you find the package, install it into your r
environment:
conda install -n R r-extrafont
If the package does not have a conda-forge feedstock, yet, consider contributing by creating a conda-forge recipt from the conda R skeleton helper.
Hello,
Thanks for the tutorial.
I didn't really understand the exact location of the
env RSTUDIO_WHICH_R
line of code.When I run :
here's the error message:
WARNING: R shared object (/home/tstervinou/miniconda3/envs/myEnv/lib/R/lib/libR.so) failed load test with error:
Linux may have loaded a different libR.so than requested. This can result in "package was built under R version X.Y.Z" user warnings and R_HOME/R version mismatches.
R_HOME: /home/tstervinou/miniconda3/envs/myEnv/lib/R
R Version: 4.3.1. Please contact your system administrator to correct this libR.so install.
I think my Rstudio can't define the right version of R (r-base=4.2.2 of conda), but I can't solve this problem,
Do you have any idea what the problem is and/or can you show me the modified rstudio.desktop file so that I can understand my error?
Thanks in advance and have a nice day,
TS