Chapter 5 Installing RStudio and R
RStudio is a powerful IDE specifically designed for working with R. In this chapter, we’ll install both R (the language) and RStudio (the interface).
Important order:
You must install R first, then RStudio second. RStudio needs R to work!
Think of it like: - R = The engine - RStudio = The dashboard and steering wheel
5.1 Part 1: Installing R
5.1.1 Step 1.1: Download R
Go to the Comprehensive R Archive Network (CRAN):
5.1.1.1 For Windows Users
- Click “Download R for Windows”
- Click “base”
- Click “Download R-4.x.x for Windows” (version number may vary)
5.1.1.2 For macOS Users
- Click “Download R for macOS”
- Choose the appropriate version for your Mac:
- Apple Silicon (M1/M2/M3): Download
R-4.x.x-arm64.pkg - Intel Macs: Download
R-4.x.x-x86_64.pkg
- Apple Silicon (M1/M2/M3): Download
Not sure which Mac you have?
Click Apple menu () → About This Mac: - If you see “Chip: Apple M1” (or M2/M3) → Download arm64 version - If you see “Processor: Intel” → Download x86_64 version
5.1.2 Step 1.2: Install R
5.1.2.1 Windows Installation
- Locate the downloaded
.exefile (e.g.,R-4.4.0-win.exe) - Double-click to launch the installer
- Language: Select “English” (or your preference)
- Click “Next” through the setup wizard
- Installation directory: Keep the default (
C:\Program Files\R\R-4.x.x) - Components: Select “Core Files” (default is fine)
- Startup options: Choose “No” for customized startup
- Start Menu folder: Keep default
- Click “Install”
- Wait for installation to complete (~2-3 minutes)
- Click “Finish”
32-bit vs 64-bit:
Modern computers are all 64-bit. If the installer asks, choose 64-bit only.
5.1.2.2 macOS Installation
- Locate the downloaded
.pkgfile - Double-click to launch the installer
- Click “Continue” through the introduction screens
- License: Click “Continue” and then “Agree”
- Installation Type: Keep default location
- Click “Install”
- Enter your Mac password when prompted
- Wait for installation (~1-2 minutes)
- Click “Close”
macOS Security Warning:
If you see “R-4.x.x.pkg can’t be opened”, right-click the file → “Open” → Click “Open” again in the security dialog.
5.1.3 Step 1.3: Verify R Installation
Let’s make sure R installed correctly!
5.1.3.1 Windows
- Open Command Prompt: Press
Windows+R, typecmd, press Enter - Type:
R --version - You should see something like:
R version 4.4.0 (2024-04-24)
5.1.3.2 macOS/Linux
- Open Terminal
- Type:
R --version - You should see:
R version 4.4.0 (2024-04-24 ucrt)
If R is not recognized:
- Windows: You may need to add R to your PATH. Restart your computer first, then try again.
- macOS/Linux: R should be automatically available in Terminal. If not, try running
/usr/local/bin/R --version
If still not working, try reinstalling R and make sure to check “Add R to PATH” during installation.
5.2 Part 2: Installing RStudio
Now that R is installed, let’s install RStudio!
5.2.1 Step 2.1: Download RStudio Desktop
Go to the Posit (formerly RStudio) download page:
https://posit.co/download/rstudio-desktop/
The website should auto-detect your operating system. Click the big blue button:
- Windows: “Download RStudio for Windows”
- macOS: “Download RStudio for macOS 11+”
- Linux: “Download RStudio for Ubuntu 22/Debian 11”
Need a different version?
Scroll down to “All Installers and Tarballs” to find other OS versions.
5.2.2 Step 2.2: Install RStudio
5.2.2.1 Windows Installation
- Locate the downloaded
.exefile (e.g.,RStudio-2024.04.0-735.exe) - Double-click to launch the installer
- Click “Next” on the welcome screen
- Installation folder: Keep default (
C:\Program Files\RStudio) - Start Menu folder: Keep default
- Click “Install”
- Wait for installation (~1-2 minutes)
- Click “Finish”
5.2.3 Step 2.3: First Launch of RStudio
When you first open RStudio, you’ll see a four-panel interface:
RStudio’s Four Panels:
- Console (bottom-left): Where you run R commands interactively
- Source (top-left): Where you write and edit R scripts (may not appear until you open a file)
- Environment/History (top-right): Shows variables, data, and command history
- Files/Plots/Help (bottom-right): File browser, plots, packages, and help documentation
5.2.4 Step 2.4: Test RStudio
Let’s run your first R code!
- In the Console (bottom-left), click after the
>prompt - Type this code and press Enter:
You should see the output: [1] "Hello from RStudio!"
- Try a simple calculation:
Output: [1] 15
- Create a variable:
Output: [1] 50
Everything working?
If you see the outputs above, congratulations! R and RStudio are installed and working correctly. 🎉
If you see errors like “R not found” or RStudio won’t open, try: - Restarting your computer - Reinstalling R first, then RStudio - Checking that you installed both (not just one)
5.3 Step 3: Configure RStudio Settings
Let’s optimize RStudio for this course.
5.3.2 3.2 Recommended Settings
5.3.2.1 General → Basic
- Save workspace to .RData on exit: Select “Never”
Why disable .RData?
This ensures you always start with a clean workspace and your code is fully reproducible. It’s a best practice for data analysis!
5.4 Step 4: Install Essential R Packages
R packages extend R’s functionality. Let’s install the packages you’ll need for this course.
5.4.1 4.1 Install Tidyverse
Tidyverse is a collection of R packages for data science. In the RStudio Console, run:
This will take 5-10 minutes to install. You’ll see lots of text scrolling by — that’s normal!
Mirror selection:
RStudio may ask you to choose a CRAN mirror. Select one close to you (e.g., “USA (TN)” for Tennessee) or “0-Cloud” for automatic selection.
5.4.2 4.2 Install Additional Course Packages
Run these commands one at a time in the Console:
# Statistical modeling packages
install.packages("car") # Type III ANOVA
install.packages("emmeans") # Post-hoc comparisons
install.packages("lme4") # Mixed models
# Design of experiments
install.packages("FrF2") # Factorial designs
install.packages("agricolae") # Agricultural statistics
# Data manipulation and visualization (if not in tidyverse)
install.packages("dplyr")
install.packages("ggplot2")
# Reporting and documentation
install.packages("knitr")
install.packages("rmarkdown")
install.packages("quarto") # We'll also install Quarto separatelyInstallation taking forever?
- Use a wired internet connection if possible (faster than Wi-Fi)
- Close other programs to free up memory
- You can install packages one at a time if bulk installation fails
- Some packages have many dependencies — this is normal!
5.4.3 4.3 Verify Package Installation
After installation, test that packages load correctly:
You should see a message like:
── Attaching core tidyverse packages ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.0 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2
Common error:
Error in library(tidyverse) : there is no package called 'tidyverse'
Solution: The package didn’t install. Run install.packages("tidyverse") again.
5.5 Video Tutorial: Installing R and RStudio
Video not loading?
Watch on YouTube: How to Install R and RStudio