Chapter 1 Setting up your computer

We’ll be using a variety of different software programs to write, manage, and execute the code that we write. Unfortunately, one of the most frustrating and confusing barriers to working with code is simply getting your machine properly set up. And you cannot even continue before you have got the necessary tools up and running! This chapter aims to provide sufficient information for setting up your machine and troubleshooting the process. All the tools we use are free to use, and they work on all major platforms, including linux, mac and windows.

Below, through this book, you’ll need to the following software:

  • R: a popular programming language for working with data. This is the primary programming language used throughout this book. “Installing R” actually means installing tools that will let your computer understand and run R code.

  • RStudio: A graphical editor (IDE or Integrated Development Environmnet) for writing and running R code. This will soon become our primary development application. Strictly speaking, RStudio is not necessary, you can perfectly work with R without it, but it simplifies the work quite a bit. Through the book, we assume you are using RStudio.

Next we explain these programs in mode detail.

1.1 R Language

The primary programming language you will use throughout this book is called R. It’s a powerful programming language that is designed for statistics and for working with data. See Section 2 for a more in-depth introduction to the language.

In order to use R programs on your computer, you need to install the R Interpreter on your machine. This is a piece of software that is able to “read” code written in R and use that code to control your computer. Such controlling is called “programming”.

The easiest way to install R is to download it from the Comprehensive R Archive Network (CRAN) at https://cran.r-project.org/. Click on the appropriate link for your operating system in order to find a link to the installer.

download R for mac

Downloading R for Mac. R 4.3.3 was the latest version as of the time of writing, but you should always get the most recent one. Download the blue .pkg file that corresponds to your computer cpu type.

  • On a Mac, you’re looking for the .pkg file—get the latest version supported by your computer. You also need to use either intel or M1/M2 (Apple silicon) version, depending on your computer type. (If you are not sure, you can find it using “About this mac” in the Apple menu.)

    To ensure smooth programming with R and RStudio on macOS, you will need to download and install Xquartz. This application supports R functions that were removed in later macOS versions and is essential for using R in the terminal. Note that before macOS 10.8, Xquartz was included by default, so if you have an older macOS then it may already be installed. But you may still check.

  • On Windows, follow the link to the base subdirectory (or follow the link to “install R for the first time”), then click the link to download the latest version of R (the link titled Download R-4.3.3 for Windows as of the time of this writing). This will download the .exe installer, you will need to double-click on it to install the software. Accept the default options, unless you know better.
  • There are binary versions for popular linux distributions, including ChromeOS. Many distros also include R through they package managers.

1.2 RStudio

While you are able to execute R scripts with just the R program you downloaded above, RStudio provides a wonderful way to engage with the R language. RStudio is described in more detail in Section 2.2.

A selection of different installers on the RStudio download page.

To install the RStudio program, you first need to install R (see above). Thereafter select the installer for your operating system from the RStudio downloads page. Make sure to download the free version, and the correct version for your OS. Note: it may suggest to download the windows version, so scroll down and pic another option if you use mac/linux.

Once the download completes, double-click on the .exe or .dmg file to run the installer. Accept the default options and the default R installation if asked. Now you should be prepared to use RStudio.