This guest post was written by the most excellent data scientist Martin Frigaard. Hit him on on twitter @mjfrigaard.
Being bilingual has been shown to increase people’s ability to focus and concentrate, solve problems, and have better mental flexibility.
It’s also important that data scientists limit themselves to relying on a single programming language for data management, visualization, modeling, and deployment.
JupyterLab is a web-based interactive development environment for data analysis, scientific computing, and predictive modeling.
Step 1 - Install Anaconda
First we need to download and install the Anaconda from this website
After downloading and installing Anaconda, open a new macOS Terminal and make sure everything was installed correctly by entering the following commands:
This should open your web browser with the following display in your browser. We are using Brave.
The Anaconda environment has sections for opening a Python Kernel in
- A Jupyter Notebook or
- The Console.
Python is run via Jupyter’s kernel, which you can read about here.
Under Other section, there are also options for starting a
bash shell session, creating new text or markdown files, or getting contextual help.
Step 2 - Install the necessary R packages
There are seven packages we need to install to setup the R Kernel in the Jupyter Lab environment.
repr: String and binary representations of objects for several formats mime types.
IRdisplay: An interface to the rich display capabilities of ‘Jupyter’ front-ends (e.g. ‘Jupyter Notebook’) https://jupyter.org. Designed to be used from a running ‘IRkernel’ session https://irkernel.github.io.
evaluate: Parsing and evaluation tools that make it easy to recreate the command line behavior of R.
pbdZMQ: pbdZMQ is an R package providing a simplified interface to ZeroMQ with a focus on client/server programming frameworks. Notably, pbdZMQ should allow for the use of ZeroMQ on Windows platforms.
devtools: Collection of package development tools.
uuid: Tools for generating and handling of UUIDs (Universally Unique Identifiers).
digest: digest provides `hash’ function summaries for GNU R objects.
IRkernel: R kernel for Jupyter
These packages can be installed by running the code below in the R console.
After we’ve installed these packages, we need to find our version of R on our local machine. On macOS, it is usually located in the
We use the pwd command in Terminal to show where the application is, and then use
open R to launch a session of R in the Terminal.
This is the R session in the Terminal window.
After these have been installed, we need to close the JupyterLab environment by exiting out of the browser. We will also need to close the Jupyter Kernel in the Terminal by clicking on
ctrl + c and then
Start another JupyterLab session and you should see the option for an R Kernel under the Notebook and Console sections.
Step 3 - Launch an R Kernel from Jupyter
Now we want to launch the R Kernel and enter some R code to make sure everything is working. We can test the R Kernel in a Notebook, because Jupyter notebooks give us the ability to insert R code, markdown, or plain text code cells.
These are similar to code chunks in Rmarkdown interrupted
##Running R from Jupyter Notebook
We now have an R Kernel running in Jupyter Lab. The code below loads the popular
tidyverse package from RStudio.
We can write in markdown or code, just like the Python environment.