Jupyter notebook

Draft

Jupyter notebook, python. A “web-based computational environment”

Project homepage: https://jupyter.org/

Wikipedia

Besides the python kernel, Jupyter kernels include

Cytoscape

SageMATH

and, of course R, which along with python and Julia, is one of the core programming languages available in Jupyter. We present how to install the IRkernel on this page.

In the cloud

Access to Jupyter notebook was discussed for running R in the cloud.

Local installation

# install latest python 3.12.4
# https://www.python.org/

# https://www.python.org/downloads/windows/
# macOS universal installer
# https://www.python.org/downloads/macos/

# default python on macOS
# see how to bash alias at https://stackoverflow.com/questions/18425379/how-to-set-pythons-default-version-to-3-x-on-os-x

# Open terminal
python3 –version
python3 -m pip –version
# pip3 install jupyterlab

pip install jupyterlab
jupyter lab
browser opens http://localhost:8888/lab

Install IRkernel from CRAN

# Run R in terminal as administrator
sudo R
# At R prompt enter
install.packages(“IRkernel”)
# Making the kernel available to Jupyter
IRkernel::installspec(user = FALSE)

Run R as Jupyter Notebook

In the terminal, type at the bash shell line

jupyter lab

start jupyter lab in terminal

Figure cc. Screenshot of terminal with command

Set working drive, then load kernel. Select the R kernel and create a new Notebook, Figure cc  (i.e., don’t select a Console, Fig. cc).

jupyter start page, select kernel

Figure cc. Screenshot of Jupyter Lab. Select R icon under Notebook to set IRkernel.

Ready to go, Figure cc.

R Jupyter Notebook

Figure cc. Screenshot of Jupyter Notebook running the IRkernel.

R running as Console in Jupyter

Figure cc. Screenshot of Jupyter Console running the IRkernel.

It’s easy to switch kernels. Let’s say you started Jupyter Lab and notice that Python is running (Fig. cc). Click on the kernel name — see green arrow in Figure cc — to bring up a popup menu, Fig cc.

identify kernel

Figure cc. Screenshot of Notebook with Python set as kernel.

switch kernel popup menu

Figure cc. Screenshot of select kernel popup menu

Click on the drop arrow and select R kernel (figure cc), then click on blue Select button (see Figure cc).

switch kernel, select R

Figure cc. Screenshot of installed kernels

Once

kernel set to R