RStudio and R
R
We recommend using R via Conda, as its much more stable in your lab. This page contains guides on how you can setup R through Conda in your workbench
How to create R environment
Here's an example on how to create a Conda environment with R and R-IRkernel kernel and commonly used packages, paste this into your terminal in workbench. Feel free to remove or add other packages if you wish:
bash
mamba create -n <name> 'r-base>=4.0,<5.0' 'r-irkernel' 'r-devtools' 'r-remotes' 'r-dplyr' 'r-tidyverse' 'r-haven' 'r-languageserver' 'r-lintr' 'cmake' 'compilers' 'cmake' 'gmp'Rstudio
RStudio is configured to use packages installed in the conda environment named r-base.
R packages
You can identify your current R version packages in your Workbench Terminal following these steps:
- Open your Workbench Terminal.

- List the packages in your
r-baseconda environment.
bash
conda list -n r-baseHow to install R packages
If you want to install your own R packages, we recommend that you use Conda where ever possible:
- Open Workbench Terminal:

- Activate r-base environment
bash
conda activate r-base- Add packages to your
r-basecode environment:
bash
# -- Principal example
conda install -n r-base -c conda-forge r-'<package-name>' r-'<another-package-name>'
# -- Practical example*
conda install -n r-base -c conda-forge r-dplyrFor example, the above example installs the dplyr package.
- When the installation is complete, open RStudio or R in your workbench (look further down for guide on how to use R in terminal) and load your new package:
bash
# -- Principal example
library(<package-name>)
# -- Practical example
library(dplyr)You can defer to alternative methods such as install.packages() when the package is not available in Conda (see below).
How do I install R packages not found in Conda?
If you don't find a R package in Conda as described above, you may need to defer to running the install.packages() command inside R. We recommend to use R in your workbench terminal for such installations (instead of installing directly in RStudio) to avoid broken environment states in RStudio. Packages installed into your r-base environment through R in terminal should be available in RStudio.
Packages installed into r-base environment through R in terminal will be available in RStudio.
Make sure to activate the r-base environment before running R command.
bash
conda activate r-baseHow can I use R in my Workbench Terminal?
First, open your Workbench Terminal.
Start by activating r-base environment:
bash
conda activate r-baseThen run R inside your r-base environment:
bash
REnjoy!
How can I recover my R environment in case of broken package installation?
Sometimes you may get errors about the GLIBCXX library not being found and/or essential R packages are not working. This happens typically after installation of custom package. In such cases, you might consider to recreate your r-base environment from scratch:
- Open your workbench terminal and run the following code to reset your
r-baseenvironment:
bash
mamba create --yes -n r-base 'r-base>=4.0,<5.0' 'compilers' 'cmake' 'gmp' 'r-irkernel' 'r-devtools' 'r-remotes' 'r-dplyr' 'r-tidyverse' 'r-haven' 'r-languageserver' 'r-lintr'If you have older setup without mamba, use conda command instead:
bash
conda create --yes -n r-base 'r-base>=4.0,<5.0' 'compilers' 'cmake' 'gmp' 'r-irkernel' 'r-devtools' 'r-remotes' 'r-dplyr' 'r-tidyverse' 'r-haven' 'r-languageserver' 'r-lintr'WARNING
This removes custom packages that you might have installed.