2  Setting Up Your Computer

Published

November 4, 2024

2.1 Objectives

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

2.2 What are you asking me to install?

It’s generally 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 A statistical programming language built around working with data
Python A general-purpose programming language that is popular for machine learning tasks.
RStudio IDE An integrated desktop environment created to make it easy to work with R, Python, and other data-science programming tools.
Quarto 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 A version control system used to track changes to files.
GitHub An online collaboration platform based on git that makes it easy to back up, share, and collaborate on programming projects.

2.3 Why do I need to install this stuff?

Presumably, if you’re reading this book, you either want to know how to do some statistical programming task, or you’re taking a class on statistical programming that is using this textbook. Hopefully, if you’re reading this for a class, you also want to learn how to work with data in some fashion. 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 executive 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.4 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. Download and run the R installer for your operating system from CRAN:

    If you are on Windows, you should also install the Rtools4 package; this will ensure you get fewer warnings later when installing packages.

    If you are on Mac, you should also install XCode, which is a set of developer tools. You can get it from the App store, but it’s better to set yourself up with Homebrew and then use homebrew to install XCode. 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.

/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
  1. Download and install the latest version of python 3

    • 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. 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.

  3. 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 necessary depending on which class you’re in. If you want to be safe, go ahead and complete these steps as well.

  1. Install git using the instructions here. Consult the troubleshooting guide if you have issues. If that fails, then seek help in office hours.

  2. Install LaTeX and rmarkdown:

    • Launch R, and type the following commands into the console:
    install.packages(c("tinytex", "knitr", "rmarkdown", "quarto"))
    library(tinytex)
    install_tinytex()
Your turn

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:
install.packages(
  c("tidyverse", "rmarkdown", "knitr", "quarto")
)
  • Can you find the text editor?
    • Create a new quarto document (File -> New File -> Quarto Document).
    • 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.