Install R & RStudio

Why R & RStudio?

R is the industry standard for statistical analysis, data visualization, and reproducible research in mass communications. RStudio is the professional interface that makes R accessible and powerful. Together, they’re essential tools for any Communication Liaison who works with data.

In this course, you’ll use R to: - Clean and analyze data from surveys and content analysis - Create publication-ready visualizations and reports - Build reproducible workflows for your research - Collaborate on data analysis projects


What You’ll Install

  1. R — The programming language (free, open-source)
  2. RStudio — The professional development environment (free, open-source)

This is a two-step process: install R first, then RStudio.


Step 1: Install R

For Windows

  1. Go to r-project.org
  2. Click “Download R” in the left menu
  3. Click the “Download R for Windows” link
  4. Click “base”
  5. Click “Download R X.X.X for Windows” (where X.X.X is the latest version number)
  6. Run the installer (.exe file)
    • Click “Next” through all screens
    • Accept the default installation location
    • Accept all default components
  7. Click “Finish”

To verify installation: - Open PowerShell or Command Prompt - Type R --version - You should see R’s version information

For macOS

  1. Go to r-project.org
  2. Click “Download R” in the left menu
  3. Click “Download R for macOS”
  4. Download the appropriate .pkg file for your Mac:
    • Apple Silicon (M1/M2/M3 chips): Download the “ARM64” version
    • Intel Macs: Download the “Intel 64” version
    • Not sure? Click the Apple icon (top left) → “About This Mac” → check under “Processor”
  5. Run the installer (.pkg file)
    • Click through all prompts
    • Accept the default installation location
  6. Restart your Mac

To verify installation: - Open Terminal - Type R --version - You should see R’s version information

For Linux (Ubuntu/Debian)

Open Terminal and run:

sudo apt update
sudo apt install r-base

To verify: Type R --version in Terminal.


Step 2: Install RStudio

For Windows, macOS, or Linux

  1. Go to posit.co/download/rstudio-desktop/
  2. Scroll down to “All Installers” or “Download RStudio Desktop”
  3. Select your operating system:
    • Windows: Download the .exe file
    • macOS: Download the .dmg file
    • Linux: Download the appropriate .deb or .rpm file
  4. Run the installer
    • Windows: Click through all default options
    • Mac: Drag RStudio to Applications folder
    • Linux: Follow the package manager prompts
  5. Open RStudio (you should see R is installed when you open it)

Step 3: Verify RStudio Works

  1. Open RStudio (should be in your Applications/Programs menu)
  2. You should see four panes:
    • Top left: Script editor (blank)
    • Bottom left: Console (shows > prompt)
    • Top right: Environment & History
    • Bottom right: Files, Plots, Packages, Help
  3. In the Console (bottom left), type this command and press Enter:
print("Hello, Communication Liaison!")
  1. You should see the output:
[1] "Hello, Communication Liaison!"

If you see this output, you’re ready to go!


Step 4: Install Key Packages

RStudio comes with base R, but you’ll need additional packages for data analysis. Open RStudio and copy these commands into the Console one at a time:

For Data Analysis & Visualization

install.packages("tidyverse")

This installs a collection of packages including: - ggplot2 — Create professional visualizations - dplyr — Clean and transform data - readr — Import data from CSV, Excel, etc. - tidyr — Reshape data

Wait for it to finish (you’ll see a blank > prompt when done)

For Survey Analysis

install.packages("likert")

Used for analyzing Likert-scale survey responses.

For Reporting

install.packages("rmarkdown")

Creates professional PDF and HTML reports from your analysis.

Optional: Statistics Packages

For later phases, you might want these too:

install.packages("lm.beta")  # Standardized regression coefficients
install.packages("car")       # Post-hoc tests and diagnostics
install.packages("ggstatsplot")  # Statistical plots with test results

Step 5: Create Your First R Project

RStudio projects help you organize your work. Let’s create one:

  1. In RStudio, click FileNew Project
  2. Select New DirectoryNew Project
  3. Name your project mc451-research or similar
  4. Choose where to save it (suggest Documents)
  5. Click Create Project

You should now see your project name in the top-right corner of RStudio.


Step 6: Test Your Setup with Data

Let’s make sure everything works by loading a dataset:

In the Console, type:

# Load the tidyverse library
library(tidyverse)

# Load a built-in dataset
data(mtcars)

# View the first few rows
head(mtcars)

You should see a table with car data. If this works, your R setup is complete!


Understanding the RStudio Interface

Area Purpose
Top Left (Script Editor) Write R code here and save as .R files
Bottom Left (Console) Results appear here; you can type commands directly
Top Right (Environment) Shows all variables and data you’ve loaded
Bottom Right (Files/Plots/Help) Navigate files, view plots, access documentation

Basic RStudio Workflow

  1. Create a new script: File → New File → R Script
  2. Write code: Type your commands in the script
  3. Run code: Select lines and press Ctrl+Enter (Windows/Linux) or Cmd+Enter (Mac)
  4. See results: Output appears in the Console or Plots pane
  5. Save your work: Ctrl+S or File → Save

Common First-Time Issues

“Command not found: R”

Problem: Your computer doesn’t recognize the R command.

Solution: - Try restarting your computer after installation - Check that R installed correctly (reinstall if needed) - On Mac/Linux, you may need to use /usr/bin/R instead

RStudio Opens But Doesn’t Find R

Problem: RStudio says “R not found” when you open it.

Solution: 1. Make sure you installed R first (before RStudio) 2. In RStudio, go to ToolsGlobal OptionsGeneral 3. Under “R sessions”, check the “R home directory” 4. If empty, browse to your R installation folder and select it 5. Click “OK”

“Error: Could not find function”

Problem: You get an error like could not find function "ggplot"

Solution: You need to load the package first. Run:

library(ggplot2)  # or whichever package you need

Installation Stuck or Takes Forever

Problem: install.packages() command seems frozen.

Solution: 1. Press Escape to stop it 2. Try installing from a different CRAN mirror:

install.packages("tidyverse", repos="https://cloud.r-project.org")

“Permission denied” Error (Mac/Linux)

Problem: Error when installing packages.

Solution: Try:

Sys.which("R")  # Check where R is installed

If you’re still stuck, reach out during office hours.


Next Steps

  1. ✅ Installed R
  2. ✅ Installed RStudio
  3. ✅ Verified it works
  4. ✅ Installed key packages
  5. Next: Learn R basics with your first assignment in Phase 2

Resources


Questions?

R and RStudio have a learning curve, but the payoff is huge. If you run into issues:

  1. Check the troubleshooting section above
  2. Search stackoverflow.com for your error (others have likely encountered it)
  3. Visit office hours—we’ll debug together
  4. Email with your specific error message

You’ve got this! 💪