Chapter 12 Moving to your own machine
Throughout this book, we have assumed that you are working on a web-based platform (e.g., JupyterHub) that already has Jupyter, R, a number of R packages, and Git set up and ready to use. In this chapter, you’ll learn how to install all of that software on your own computer in case you don’t have a preconfigured JupyterHub available to you.
12.2 Chapter learning objectives
By the end of the chapter, students will be able to:
- install Git and the miniconda Python distribution
- install and launch a local instance of JupyterLab with the R kernel
- download files from a JupyterHub for later local use
12.3 Installing software on your own computer
In this section we will provide instructions for installing the software required by this book on our own computer. Given that installation instructions can vary widely based on the computer setup we have created instructions for multiple operating systems. In particular, the installation instructions below have been verified to work on a computer that:
- runs one of the following operating systems: MacOS 10.15.X (Catalina); Ubuntu 20.04; Windows 10, version 2004.
- can connect to networks via a wireless connection
- uses a 64-bit CPU
- uses English as the default language
For macOS users only: Apple recently changed the default shell in the terminal to Zsh. However, the programs we need work better with the Bash shell. Thus, we recomend you change the default shell to Bash by opening the terminal (how to video) and typing:
chsh -s /bin/bash
You will have to quit all instances of open terminals and then restart the terminal for this to take effect.
As shown in the version control chapter, Git is a very useful tool for version controlling your projects, as well as sharing your work with others.
Windows: To install Git on Windows go to https://git-scm.com/download/win and download the windows version of git. Once the download has finished, run the installer and accept the default configuration for all pages.
MacOS: To install Git on Mac OS open the terminal and type the following command:
Ubuntu: To install Git on Ubuntu open the terminal and type the following commands:
sudo apt update sudo apt install git
To run Jupyter notebooks on our computers we will need to install a program similar to the one we used as our web-based platform. One such program is JupyterLab. But JupyterLab relies on Python; we can install this via the miniconda Python package distribution.
Windows: To install miniconda on Windows, download
the Python 3.8 64-bit version from here.
Once the download has finished, run the installer and accept the default
configuration for all pages. After installation, you can open the Anaconda Prompt
by opening the Start Menu and searching for the program called
“Anaconda Prompt (miniconda3)”. When this opens you will see a prompt similar to
MacOS: To install miniconda on MacOS, download the Python 3.8 64-bit version from here. After the download has finished, run the installer and accept the default configuration for all pages.
Ubuntu: To install miniconda on Ubuntu, we first download the Python 3.8 64-bit version from here. After the download has finished, open the terminal and execute the following commands:
Note: most often this file is downloaded to the Downloads directory, and thus the command will look like this:
The instructions for the installation will then appear:
- Press Enter.
- Once the licence agreement shows, you can press space scroll down, or press
qto skip reading it.
yesand press enter to accept the licence agreement.
- Press enter to accept the default installation location.
yesand press enter to instruct the installer to run
conda init, which makes
condaavailable from the terminal/shell.
With miniconda set up, we can now install JupyterLab and the Jupyter Git extension. Type the following into the Anaconda Prompt (Windows) or the terminal (MacOS and Ubuntu) and press enter:
conda install -c conda-forge -y jupyterlab conda install -y nodejs=10.* pip install --upgrade jupyterlab-git jupyter lab build
To test that your JupyterLab installation is functional, you can type
jupyter lab into the Anaconda Prompt (Windows) or terminal (MacOS and Ubuntu) and press enter. This should open a new
tab in your default browser with the JupyterLab interface. To exit out of
JupyterLab you can click
File -> Shutdown, or go to the terminal from which
you launched JupyterLab, hold
Ctrl, and press
12.3.4 R and the IRkernel
To have R available to you in JupyterLab, you will need to install the R programming language and the IRkernel. To install these, type the following into the Anaconda Prompt (Windows) or terminal (MacOS and Ubuntu):
conda install -c conda-forge -y r-base conda install -c conda-forge -y r-irkernel
To improve the experience of using R in JupyterLab, we will add an extension
that allows us to setup keyboard shortcuts for inserting text.
By default, this extension creates shortcuts for inserting two of the most common R
%>%. Type the following in the Anaconda Prompt (Windows)
or terminal (MacOS and Ubuntu) and press enter:
jupyter labextension install @techrah/text-shortcuts jupyter lab build
12.3.5 R packages
To install the packages used in this book, type the following in the Anaconda Prompt (Windows) or terminal (MacOS and Ubuntu) and press enter:
conda install -c conda-forge -y \ r-cowplot \ r-ggally \ r-gridextra \ r-infer \ r-kknn \ r-rodbc \ r-rpostgres \ r-rsqlite \ r-testthat \ r-tidymodels \ r-tinytex \ unixodbc
To be able to render
.ipynb files to
light-weight cross-platform, portable, and easy-to-maintain LaTeX distribution
based on TeX Live. To install it open JupyterLab by typing
in the Anaconda Prompt (Windows) or terminal (MacOS and Ubuntu) and press enter.
Then from JupyterLab open an R console and type the commands listed below and
press Shift + enter to install
tinytex::install_tinytex() tinytex::tlmgr_install(c("eurosym", "adjustbox", "caption", "collectbox", "enumitem", "environ", "fp", "jknapltx", "ms", "oberdiek", "parskip", "pgf", "rsfs", "tcolorbox", "titling", "trimspaces", "ucs", "ulem", "upquote"))
12.4 Moving files to your computer
In the course that uses this textbook, students work on a web-based platform (a JupyterHub) to do their course work. This section is to help students save their work from this platform at the end of the course.
First in JupyterHub, open a terminal by clicking “terminal” in the Launcher tab.
Next, type the following in the terminal to create a
.zip archive for the course work you are interested in downloading:
zip -r course_folder.zip your_course_folder
After the compressing process is complete, right-click on
in the JupyterHub file browser
and click “Download”. You should be able to use your computer’s software to unzip
the compressed folder by double-clicking on it.