Introduction to R on some Jupyter notebooks. Based on the DMA Unit 2 course @ Sapienza
In order to make the Jupyter Notebooks run, it's important to install the R
kernel. In order to do so, I followed these steps (mind that some of them might not be necessary, but in order to have a self-contained envorinment they might prove to be useful):
- Install
R
from here; - Install Anaconda or Miniconda;
- Create a virtual environment;
-
Install the following packages with
conda
:conda install python=3.7.13 r pip
-
Install the following packages with
pip
:pip install jupyterlab notebook
-
Install the following packages on
R
:install.packages("jsonlite") install.packages("IRkernel")
-
- Run the following command on
R
:IRkernel::installspec()
Warning
If the previous command gives you an error, try to do the following:
- Open a terminal and run as an administrator the
R
console;
sudo R
- Run the following commands:
install.packages("devtools")
devtools::install_github("IRkernel/IRkernel")
IRKernel::installspec()
Now VSC should be able to recognize the R
kernel. You can proceed with step 5
-
Open VSC and create a new Jupyter file. When prompted to select a kernel, go to
Select Another Kernel...
→Jupyter Kernel...
→R
-
That's it! Enjoy using
R
on a Jupyter notebook!