Getting started with R and RStudio

This chapter will show you how to install R and RStudio.

Background

Why do we want to learn and use R and RStudio

R and Rstudio are powerful tools for statistical analysis. R is an open-source language, meaning it is both free and supported by a large, active community. RStudio provides an intuitive and user-friendly interface, making using R more productive. The R package (more on this later) ecosystem allows users to extend its functionality for various types of analysis. Additionally, it facilitates reproducible code and reports and allows researchers to share their work with others.

What is R and RStudio

R is a free software environment for statistical computing and graphics. RStudio is an integrated development environment (IDE) for R. To understand why we might want to use R with RStudio. We will use the analogy from Modern Dive book.

At its simplest, R is like a car’s engine while RStudio is like a car’s dashboard

R installation

First, install R. The R language is available through the The Comprehensive R Archive Network website. In the next sections, we will show how to install R for different operating systems: Windows, MacOS, and Linux.

Windows

Steps:

  1. Click “Download R for Windows”

  1. Click “base”

  1. Click the link at the top of the page. It should say something like “Download R-4.4.1 for Windows”, where the numbers would change to the latest version.

  1. Run the downloaded executable file.

  1. Allow the installer to change your device.

  1. Follow the prompt instructions. You do not need to customise the startup.

MacOS

Steps:

  1. Click “Download R for macOS”

  1. Under the “Latest release:”, click the .pkg base on your system architecture. If you are using Apple silicon (M1 onwards) Macs, click the “R-4.41-arm64.pkg”, otherwise, click the “R-4.4.1-x86_64.pkg”.

  1. After finishing downloading the .pkg, double-click on it.

  1. Follow the installer’s instructions. It will involve reading through some documents and clicking continue or install.

  1. Once the installation is complete, click “Close” to exit the installation process.

Linux

Steps:

  1. Click “Download R for Linux”.

  1. Click on the directory based on the Linux version you have.

  1. Follow the instructions on the website.

RStudio installation

The RStudio can be downloaded from the Posit website. Scroll down to All Installers and Tarballs and download the RStudio version for your operating system.

Windows

Steps:

  1. Click the .exe file. It should look similar to “RSTUDIO-2024.04.2-764.EXE”. The number will be different based on the latest version.

  1. Run the executable file to install RStudio.

  1. Allow the installer to make changes on your computer.

  1. Follow the prompts.

  2. Search for RStudio on your computer and open it. You are now ready to learn R!

MacOS

Steps:

  1. Click the .dmg file. It should look similar to “RSTUDIO-2024.04.2-764.DMG”. The number will be different based on the latest version.

  1. Drag RStudio.app into the Applications folder. Now you are ready to use R!

Linux

Steps:

  1. Click download the file based on your Linux version.

  1. Follow the instructions prompts.