2  Setting Up Your Computer

Published

August 23, 2025

Objectives

  • Set up RStudio, R, Quarto, and python
  • Be able to run demo code in R and python

2.1 What are you asking me to install?

It’s a good idea to be skeptical when someone is telling you to install things. 🤨 Here’s a very broad overview of what each of these programs or services does and why I’m asking you to install or sign up for them.

What each program does, in general terms
Program Logo Purpose
R R logo A statistical programming language built around working with data
Python Python logo A general-purpose programming language that is popular for machine learning tasks.
RStudio IDE RStudio logo An integrated desktop environment created to make it easy to work with R, Python, and other data-science programming tools.
Quarto Quarto logo A document creation system based on pandoc. Quarto allows you to include code, results, and pictures generated from data within a document so that they automatically update when the document is recompiled.
Git git logo A version control system used to track changes to files.
GitHub GitHub logo An online collaboration platform based on git that makes it easy to back up, share, and collaborate on programming projects.

2.2 Why do I need to install this stuff?

  • R is good for data wrangling, statistical programming, modeling, and data visualization
  • Python is good for machine learning, deep learning, image processing, and web scraping
  • Quarto allows you to write R and python code, keeping code and documentation in the same document
  • git is helpful for tracking changes to code and data, and for collaborating

While some parts of this book are fairly language-agnostic (R and python are both good languages for working with data), this setup is opinionated - the book focuses on a set of programs which are useful for doing statistical programming, including writing reports, keeping track of code, visualizing data, cleaning data, and getting set up for modeling data and producing results.

If you’re just trying to learn R, perhaps you don’t need to install python or quarto. If you’re not working with other people, maybe you don’t need to install git. You are welcome to make those decisions for yourself, but if you’re not sure, you might just want to install the whole toolbox - you’ll hopefully learn how to use all of the tools along the way, and it’ll be less confusing later if you already have access to all of the tools and don’t need to go back and get something else when you need it.

2.3 Installation Process

In this section, I will provide you with links to set up various programs on your own machine. If you have trouble with these instructions or encounter an error, post on the class message board or contact me for help.

  1. Get the R installer from CRAN: https://cran.rstudio.com/bin/windows/base/

  2. Install the Rtools4 package that matches the R version you installed: https://cran.rstudio.com/bin/windows/Rtools/
    For example, if you installed R 4.4.3, you should download RTools 4.4. If you installed R 4.0.1, you should install RTools 4.0.

  1. Get the R installer from CRAN: https://cran.rstudio.com/bin/macosx/

  2. Install XCode - a set of developer tools - so that you can install R packages more easily. There are two ways to do this:

  1. Get XCode from the App store directly (simple, but you may have to do other things later)
  2. Install Homebrew and then use homebrew to install XCode.1

I personally suggest option b, because Homebrew is used for a lot of different software-development related things, and having it will make life easier later.


Installing Homebrew + XCode
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install mas # Search the apple store
mas search xcode # find xcode
mas install 497799835 # install the program by ID

If you’re using a distribution like Debian, Fedora, RedHat, or Ubuntu, or a distribution derived from one of these distributions, follow the instructions below.

If you don’t know your distribution (or if you’re working on a derivative distribution, like Mint), you can figure out which set of instructions to follow by executing lsb_release -a in your system terminal.

If you’re using Arch or another distribution that isn’t derived from something listed above, google for instructions specific to your distribution - these instructions cover the most common, user-friendly distributions, but if you’ve chosen something more niche, it is assumed you can figure out how to install R. (If that isn’t the case, leave a comment below with your distribution, so I know how best to update this book.)


Installation Instructions
  1. Get the R installer from CRAN: https://cran.rstudio.com/bin/linux/ - pick your distribution, and follow the distribution-specific instructions from there.

You could install R using your package manager, but often this version is out of date. The instructions for each version will get you a more up-to-date version that will be easier to work with.

Download and install the latest version of python 3

Extra Instructions to Setup Python on Windows

check the box that asks if you want to add Python to the system path.
This will save you a lot of time and frustration. If you didn’t do this, you can follow these instructions to fix the issue (you’ll need to restart your machine).

  • If you’re interested in python, you should install Jupyter using the instructions here (I would just do pip3 install jupyterlab)
    We will not use jupyter much in this book - I prefer quarto - but the python community has decided to distribute code primarily in jupyter notebooks, so having it on your machine may be useful so that you can run other people’s code.

  • Additional instructions for installing Python 3 from Python for Everybody if you have trouble.

2.3.3 Install RStudio

Download and install the latest version of RStudio for your operating system. RStudio is a integrated development environment (IDE) for R, created by Posit. It contains a set of tools designed to make writing R, python, javascript, and other data-related code easier.

2.3.4 Install quarto

Download and install the latest version of Quarto for your operating system. Quarto is a command-line tool released by Posit that allows you to create documents using R or python, combining code, results, and written text.

The following steps may be helpful or required for your class. If you want to be safe, go ahead and complete these steps as well.

2.3.5 Install git

  1. Install git using the instructions here.
  2. Consult the troubleshooting guide if you have issues.
Mac Warning

With each OS version upgrade, you may find that git breaks. To fix it, you will have to re-install Mac command line tools. Once you do this, git will start working again. See [1] for more information.

2.3.5.1 Optional: Install a git client

Instructions

I don’t personally use a git client other than RStudio, but you may prefer to have a client that allows you to use a point-and-click interface. Some of the features are built into RStudio, but I’m sure there are other features that aren’t and I just don’t use them frequently.

2.3.5.2 GitHub: Git on the Web

Set up a GitHub Account Now

Instructions for setting up a GitHub account.

Be sure you remember your signup email, username, and password - you will need them later.

Git is a program that runs on your machine and keeps track of changes to files that you tell it to monitor. GitHub is a website that hosts people’s git repositories. You can use git without GitHub, but you can’t use GitHub without git.

Git is to GitHub what Porn is to PornHub. Specifically, GitHub hosts git repositories publicly, while PornHub hosts porn publicly. But it would be silly to equate porn and PornHub, and it’s similarly silly to think of GitHub as the only place you can use git repositories.

If you want, you can hook Git up to GitHub, and make a copy of your local git repository that lives in the cloud. Then, if you configure things correctly, your local repository will talk to GitHub without too much trouble. Using Github with Git allows you to easily make a cloud backup of your important code, so that even if your computer suddenly catches on fire, all of your important code files exist somewhere else.

Remember: any data you don’t have in 3 different places is data you don’t care about.2

2.3.5.3 Introduce yourself to git

You need to tell git what your name and email address are, because every “commit” you make will be signed. This needs to be done once on each computer you’re using.

Follow the instructions here, or run the lines below:

Note

The lines of code below use interactive prompts. Click the copy button in the upper right corner of the box below, and then paste the whole thing into the R console. You will see a line that says “Your full name:” - type your name into the console. Similarly, the next line will ask you for an email address.)

user_name <- readline(prompt = "Your full name: ")
user_email <- readline(prompt = "The address associated w your github account: ")

install.packages("usethis")
library(usethis)

use_git_config(user.name = user_name, user.email = user_email, scope = "user")

# Tell git to ignore all files that are OS-dependent and don't have useful data.
git_vaccinate() 

2.3.5.4 Set up GitHub Authentication

The next step is to tell GitHub how to recognize information from your computer, and to associate that computer with your user. To make this process as smooth as possible, we have to configure either HTTPS or SSH authentication.

SSH authentication is slightly more secure (but the reasons are very technical) and can be used for additional ID verification, while HTTPS authentication can be used over some networks which block SSH traffic. GitHub’s recommendation has apparently changed several times, but as of 2022, it seems that HTTPS is easiest to configure across platforms [2].

# Create a ssh key if one doesn't already exist
if (!file.exists(git2r::ssh_path("id_rsa.pub"))) {
  # Create an ssh key (with no password - less secure, but simpler)
  system("ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -q -N ''") 
  # Find the ssh-agent that will keep track of the password
  system("eval $(ssh-agent -s)")
  # Add the key
  system("ssh-add ~/.ssh/id_rsa")
} 

Then, in RStudio, go to Tools > Global Options > Git/SVN. View your public key, and copy it to the clipboard.

Then, proceed to github. Make sure you’re signed in.

  1. Click on your profile pic in upper right corner -> Settings -> SSH and GPG keys.
  2. Click “New SSH key”.
  3. Paste your public key in the “Key” box. Give it an informative title. For example, you might use 2025-laptop to record the year and computer.
  4. Click “Add SSH key”.

You can double-check that everything worked by opening a terminal and running ssh -T git@github.com, as described in the GitHub SSH Authentication documentation.

  1. In the R console, run:
  1. Click “Generate token” in the github window that appears.

  2. Copy the generated PAT to your clipboard

  3. In the R console, run:

gitcreds::gitcreds_set()

Paste your PAT in response to the console prompt.

Whichever option (HTTPS or SSH) you chose will determine which address you should select when cloning a GitHub repository.

A screenshot of the github repository for this book. The 'Code' button in the github repository has been clicked, leading to a pop-up which has tabs 'Local' (shown) and 'Codespaces' (not shown). The second set of tabs has options HTTPS, SSH (active), and GitHub CLI. There is a web address that can be copied with the address 'git@github.com:srvanderplas/stat-computing-r-python', and some help text below which says 'Use a password protected SSH key'.

When you clone a github repository, make sure to select the SSH protocol before copying the web address.

A screenshot of the github repository for this book. The 'Code' button in the github repository has been clicked, leading to a pop-up which has tabs 'Local' (shown) and 'Codespaces' (not shown). The second set of tabs has options HTTPS (active), SSH, and GitHub CLI. There is a web address that can be copied with the address 'https://github.com/srvanderplas/stat-computing-r-python.git', and some help text below which says 'Clone using the web URL'.

When you clone a github repository, make sure to select the HTTPS protocol before copying the web address.
  1. Launch R, and type the following commands into the console:
install.packages(c("tinytex", "knitr", "rmarkdown", "quarto"))
library(tinytex)
install_tinytex()

If you have an existing installation of LaTeX, using tinytex or another installer, I highly recommend that you uninstall LaTeX before re-installing the most recent version.

  1. Configure RStudio to use the tinytex installation of LaTeX:
  • Go to Tools -> Global Options -> Sweave
    The RStudio configuration pane for Sweave. The PDF generation options are as follows: Weave Rnw files using `knitr`, Typeset LaTeX into PDF using `XeLaTeX` (for font compatibility and modern rendering). The LaTeX editing and compilation options are a set of checkboxes; the two checked options are use tinytex when compiling .tex files, and Clean auxiliary output after compile. The PDF preview options can be set as you desire and are highly operating-system dependent.
Your turn: Exploring (and configuring) RStudio

Open RStudio on your computer and explore a bit.

  • Can you find the R console? Type in 2+2 to make sure the result is 4.
  • Run the following code in the R console to set up some basic packages:
install.packages(c("tidyverse", "rmarkdown", "knitr", "quarto"))
  • Run the following code in the R console to set up Python:
install.packages("reticulate")
reticulate::virtualenv_create("stat-python") # Create a python environment
reticulate::virtualenv_install("stat-python", c("numpy", "matplotlib", "pandas"))
  • Configure RStudio to use the python virtual environment you created:
    • Go to Tools -> Global Options -> Python
    • Click the Python interpreter Select button
    • Click Virtual Environments
    • Choose stat-python and hit “Select”
    • Restart RStudio when prompted to ensure the setting takes effect.
  • Test out Python:
    • Go to the Console tab, and click on the R logo. A dropdown should be present with an option to select Python.
    • Wait for the Python prompt to appear (it will look like this: >>>)
    • Type 2 + 2, hit enter, and make sure the result is 4.
  • Can you find the text editor?
    • Create a new quarto document (File -> New File -> Quarto Document).
    • Select a blank quarto document (bottom of the pop-up window)
    • Change the text editor to Source mode (it will default to visual mode). This makes it possible to paste a quarto document without Visual mode trying to “fix” the markup characters.
    • Paste in the contents of this document.
    • Compile the document (Ctrl/Cmd + Shift + K) and use the Viewer pane to see the result.
  • If this all worked, you have RStudio, Quarto, R, and Python set up correctly on your machine.
[1]
dustbuster, “Answer to "git is not working after macOS update (xcrun: Error: Invalid active developer path (/library/developer/CommandLineTools)". Stack overflow,” Sep. 26, 2018. [Online]. Available: https://stackoverflow.com/a/52522566/2859168. [Accessed: Jan. 13, 2023]
[2]
k107, “Answer to "git clone with HTTPS or SSH remote?". Stack overflow,” Jun. 15, 2022. [Online]. Available: https://stackoverflow.com/a/11041782. [Accessed: Jan. 31, 2025]

  1. If you prefer a different package manager, that’s fine - Homebrew is widely used, but there are other options. Ultimately, you just need to have XCode so that you can compile R packages.↩︎

  2. Yes, I’m aware that this sounds paranoid. It’s been a very rare occasion that I’ve needed to restore something from another backup. You don’t want to take chances. I knew a guy who had to retype his entire masters thesis from the printed out version the night before it was due because he had stored it on a network drive that was decommissioned. You don’t want to be that person.↩︎