R & RStudio Setup

Marc Los Huertos

EA030 · Compiled 2026-04-14

What Is R? Pomona Server Install R Install RStudio Pane Tour Settings First Script R Markdown Packages Shortcuts Verify

What this module covers. There are two ways to use R and RStudio in EA030: through the Pomona College server (no installation required — open a browser and go) or with a local installation on your own machine. This guide covers both paths. Most students start on the server and migrate to a local install as their work grows. By the end you will have a running environment either way and will have produced your first HTML report.


What Are R and RStudio?

R is a free, open-source programming language designed specifically for statistical computing and data visualisation. It is the dominant tool in ecology, environmental science, and the life sciences because it has specialist packages for almost every analytical task — spatial analysis, survival analysis, multivariate ordination, time series, and more.

RStudio (now maintained by Posit) is an integrated development environment (IDE) that wraps around R, adding a script editor, plot viewer, file browser, and package manager in one window. You write R code inside RStudio; RStudio sends it to R to execute.

⚠️ Order matters: install R before RStudio

RStudio needs R already installed in order to find it. If you install RStudio first and then R, RStudio may not detect it automatically. Always install R first.

Component Role Analogy Download from
R The programming language and computation engine The engine under the bonnet cran.r-project.org
RStudio The editor and interface you interact with daily The dashboard and steering wheel posit.co/download/rstudio-desktop/

Two Ways to Access RStudio

You do not have to install anything to get started. Pomona College runs an RStudio Server that gives you a full RStudio environment in your browser — R, all course packages, and persistent file storage are already configured.

⭐ Recommended to start
🌐 RStudio Server
rstudio.pomona.edu
  • Nothing to install — works in any browser
  • R, tidyverse, lme4, and all EA030 packages pre-installed
  • Files stored on the server — accessible from anywhere
  • Same R version for the whole class — consistent results
  • Works on Chromebooks, tablets, lab computers
Best for: getting started quickly, working on lab/library computers, or when local install fails.
Long-term setup
💻 Local Installation
cran.r-project.org
  • Works offline — no internet required after setup
  • Faster for large datasets and long computations
  • Full control over packages and R version
  • Required for some advanced workflows (Git, renv)
  • Stays with you after the course ends
Best for: serious or ongoing work, large datasets, and building long-term data science skills.

✅ You can use both — they are not mutually exclusive

Many students start on the server for the first few weeks, then install R locally once they are comfortable. Files can be downloaded from the server and re-uploaded to a local RStudio project at any time.


Option A — RStudio Server at Pomona

🖥️ Pomona College RStudio Server rstudio.pomona.edu

Logging in

  1. Open any modern browser (Chrome, Firefox, Safari, Edge)
  2. Navigate to https://rstudio.pomona.edu
  3. Sign in with your Pomona College credentials (the same username and password you use for Sakai, email, and the portal)
  4. The RStudio interface loads in your browser — no installation required

⚠️ Must be on the Pomona network or VPN

The server is only accessible from the Pomona campus network or through the Pomona VPN. If you are off-campus, connect to the VPN first. Download the VPN client from ITS: its.pomona.edu/network/vpn.

What is already installed

The server has R and all packages used in EA030 pre-installed and kept up to date by ITS. You do not need to run install.packages() for any of the following:

Package Purpose Verify with
tidyverse Data wrangling and ggplot2 visualisation library(tidyverse)
lme4 + lmerTest Mixed-effects models library(lme4)
car Added-variable plots, Anova() library(car)
MuMIn Model selection (AIC, R² for mixed models) library(MuMIn)
vegan Multivariate ecology (NMDS, RDA, PCA) library(vegan)
sf + terra Spatial data and raster analysis library(sf)
lubridate Date/time parsing and manipulation library(lubridate)
here Robust relative file paths library(here)
knitr + rmarkdown Reproducible reports and HTML rendering library(knitr)
ggrepel Non-overlapping plot labels library(ggrepel)
janitor Data cleaning utilities library(janitor)

If a package you need is missing, email the instructor — do not try to install it yourself, as server-wide installations require admin access.

Your home directory and file storage

Each user has a personal home directory on the server (/home/yourusername/). Files you save here persist across sessions — they are not deleted when you log out. You can see your files in the Files pane (pane 4, bottom-right).

Recommended folder structure for EA030:

/home/yourusername/
  EA030/
    data/          ← raw data files (never modify these)
    scripts/       ← .R scripts
    reports/       ← .Rmd files
    output/        ← plots, tables, rendered HTML

Create this from the Console:

dir.create("~/EA030/data",    recursive = TRUE)
dir.create("~/EA030/scripts", recursive = TRUE)
dir.create("~/EA030/reports", recursive = TRUE)
dir.create("~/EA030/output",  recursive = TRUE)

Uploading data files

To bring a data file (CSV, Excel, etc.) from your computer onto the server:

  1. In the Files pane, navigate to the folder where you want the file
  2. Click Upload (the button with an upward arrow)
  3. Click Browse, select your file, click OK

The file will appear in the Files pane and is immediately accessible from R:

# After uploading "stream_data.csv" to ~/EA030/data/
df <- read.csv("~/EA030/data/stream_data.csv")

Downloading files from the server

To download a file (e.g., your knitted HTML report) back to your computer:

  1. In the Files pane, check the box next to the file
  2. Click More → Export…
  3. Click Download

To download an entire folder as a .zip:

  1. Check the box next to the folder name
  2. Click More → Export… → Download

Knitting on the server

Knitting works identically to a local installation — click the Knit button or press Ctrl+Shift+K. The rendered HTML appears in the Viewer pane and is saved to the same directory as your .Rmd file on the server.

📌 Session timeouts

The server will suspend your R session after a period of inactivity (typically 60 minutes). Your files are always safe — only the R session (objects in memory) is cleared. When you return, click Resume to reload your session, or simply re-run your script from the top. This is one reason why self-contained, top-to-bottom scripts are important.

Server vs. local — comparison

Feature RStudio Server (rstudio.pomona.edu) Local RStudio
Setup time ⭐ Instant — just log in 15–30 minutes
Works offline ❌ Requires campus network or VPN ✅ Fully offline
Package installation Pre-installed by ITS — no action needed You manage with install.packages()
File storage On Pomona servers — persistent, backed up On your machine — you manage backups
Speed for large datasets Shared compute — may be slower under load Uses your CPU/RAM — usually faster
Git / version control Available but requires configuration ✅ Full native Git integration
Persistent objects between sessions Session suspends after inactivity ✅ Persists until you clear workspace
Access from any device ✅ Any browser, any device Only on your own computer

Option B — Local Installation

If you prefer to work locally — or need to work offline — follow the steps below to install R and RStudio on your own machine. Skip this section if you are using the Pomona server.


1
Install R
cran.r-project.org · ~80 MB · 5 minutes

Go to https://cran.r-project.org and select your operating system. Follow the tab for your platform below.

🪟 Windows
🍎 macOS
🐧 Linux

Windows

  1. Click Download R for Windows
  2. Click base
  3. Click Download R-4.x.x for Windows (the large link at the top)
  4. Run the downloaded .exe installer — accept all defaults
  5. R will install to C:\Program Files\R\R-4.x.x\

✅ 64-bit only All modern Windows machines are 64-bit. The installer detects this automatically — you do not need to choose.

macOS

  1. Click Download R for macOS
  2. Choose the correct installer for your chip:
    • Apple Silicon (M1/M2/M3) → download the arm64 .pkg
    • Intel Mac → download the x86_64 .pkg
  3. Open the .pkg and follow the installation prompts (requires admin password)
  4. R installs to /Library/Frameworks/R.framework/

To check your chip: Apple menu → About This Mac. Look for “Apple M…” (Silicon) or “Intel” in the Processor row.

⚠️ Wrong binary = crashes Mixing an Intel binary with an Apple Silicon machine (or vice versa) causes R to fail silently. Always confirm your chip before downloading.

Linux (Ubuntu / Debian)

The CRAN-maintained APT repository gives you the current R release rather than the older version packaged by Ubuntu. Run these commands in a terminal:

# 1. Add the CRAN signing key
$ wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc <br>   | sudo gpg –dearmor -o /usr/share/keyrings/r-project.gpg

# 2. Add the CRAN repository (adjust ‘noble’ for your Ubuntu codename)
$ echo “deb [signed-by=/usr/share/keyrings/r-project.gpg] <br>   https://cloud.r-project.org/bin/linux/ubuntu noble-cran40/” <br>   | sudo tee /etc/apt/sources.list.d/r-project.list

# 3. Install
$ sudo apt update && sudo apt install -y r-base r-base-dev

For Fedora/RHEL, see the CRAN Linux instructions.

Verify R is installed

After installation, open a terminal (macOS/Linux) or the R application (Windows) and type:

R.version.string

You should see something like "R version 4.4.x (2024-xx-xx)".


2
Install RStudio Desktop
posit.co/download/rstudio-desktop · ~600 MB · 5 minutes
  1. Go to https://posit.co/download/rstudio-desktop/
  2. The page should auto-detect your OS. Click Download RStudio Desktop (the free version)
  3. Run the installer and accept the defaults
🪟 Windows
🍎 macOS
🐧 Linux

Windows

Run the .exe installer. RStudio will locate your R installation automatically. Launch RStudio from the Start menu — not the R application icon.

macOS

Open the .dmg, drag RStudio to your Applications folder. On first launch, macOS may ask you to confirm — click Open. If a security dialog appears, go to System Settings → Privacy & Security and click Open Anyway.

Linux (Ubuntu/Debian)

Download the .deb installer from the Posit website and install it:

$ sudo dpkg -i rstudio-20xx.xx.x-xxx-amd64.deb
$ sudo apt-get install -f # fix any missing dependencies

✅ Confirm RStudio launched correctly

When RStudio opens, you should see the Console pane (usually bottom-left) showing a message like R version 4.4.x ... Type 'q()' to quit R. If you see an error about R not being found, R may not be on your PATH — reinstall R and reopen RStudio.


3
Tour of the Four Panes
Know where everything lives before you start

RStudio divides its window into four panes. If you only see one or two, go to View → Panes → Show All Panes (Ctrl+Shift+0 on Windows/Linux, ⌘+Shift+0 on macOS).

<div class="tab active">Untitled1.R</div>
<div class="tab">analysis.Rmd</div>
<div class="pane-label"><span class="pane-num">1</span> Source</div>
<span style="color:#6a9955"># Write your scripts here</span><br>
x &lt;- c(2, 4, 6, 8)<br>
mean(x)
<div class="tab active">Environment</div>
<div class="tab">History</div>
<div class="pane-label"><span class="pane-num">2</span> Environment / History</div>
<span style="color:#9cdcfe">x</span>
<span style="color:#888">num [1:4] 2 4 6 8</span>
<div class="tab active">Console</div>
<div class="tab">Terminal</div>
<div class="pane-label"><span class="pane-num">3</span> Console</div>
<span style="color:#3fb950">&gt;</span> mean(x)<br>
[1] 5
<div class="tab active">Plots</div>
<div class="tab">Files</div>
<div class="tab">Packages</div>
<div class="tab">Help</div>
<div class="pane-label"><span class="pane-num">4</span> Files / Plots / Help</div>
<span style="color:#888">← your plots appear here</span>
Pane What it does Key shortcut to focus
Source Write and save scripts; send code to Console Ctrl/⌘+1
Console Run commands immediately; see output Ctrl/⌘+2
Environment See all objects currently in memory Ctrl/⌘+8
Files/Plots/Help Browse files, view plots, read documentation Ctrl/⌘+9

✅ Resize panes freely Drag any divider between panes to adjust the layout. You can also zoom a single pane to full-screen with Ctrl+Shift+1 (Source) or Ctrl+Shift+2 (Console).


4
Configure Global Options
Tools → Global Options

A few settings will save you hours of debugging. Go to Tools → Global Options and make these changes:

General → Basic

📌 Why these settings matter

RStudio’s default is to save everything in memory to a hidden .RData file when you quit, then reload it next session. This sounds convenient but causes hard-to-find bugs: objects from a previous analysis silently persist and contaminate new analyses. Disabling this forces every script to be self-contained — the gold standard for reproducible science.

Code → Editing

Appearance

Choose a theme and font size that you are comfortable reading for hours. Popular choices:

Click Apply → OK when done.


5
Create an RStudio Project
Every analysis should live in a Project — it sets the working directory automatically

RStudio Projects keep your scripts, data, and outputs together and set the working directory to the project folder automatically — no more setwd("/Users/my/deeply/nested/path").

  1. Go to File → New Project
  2. Choose New Directory → New Project
  3. Name it something like EA030 and choose where to save it
  4. Click Create Project

You will see a .Rproj file appear in the Files pane. Double-clicking it from Finder/Explorer reopens the project with all your files.

✅ One project per class or analysis

For EA030, create a single project and organise it with subfolders: data/, scripts/, output/, reports/. Reference files with relative paths like read.csv("data/stream_data.csv") — they will work on any machine with the same folder structure.


6
Write and Run Your First Script
File → New File → R Script

Create a new script

Go to File → New File → R Script (or press Ctrl/⌘+Shift+N). A blank Source pane opens. Save it immediately as setup_test.R with Ctrl/⌘+S.

Run the code below

Type (or paste) the following into your script. Select all with Ctrl/⌘+A, then run with Ctrl/⌘+Enter:

# ── Basic arithmetic ──────────────────────────────────────────────
x <- c(2, 4, 6, 8, 10)         # create a numeric vector
mean(x)                          # mean
## [1] 6
sd(x)                            # standard deviation
## [1] 3.162278
summary(x)                       # five-number summary
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##       2       4       6       6       8      10
# ── A simple plot ─────────────────────────────────────────────────
plot(x, x^2,
     main = "Test Plot — x versus x²",
     xlab = "x",
     ylab = expression(x^2),
     col  = "#4a7c5e",
     pch  = 16,
     cex  = 1.5)
abline(lm(x^2 ~ x), col = "#c8832a", lwd = 2, lty = 2)

The plot should appear in the Plots pane (pane 4). Use the left/right arrows at the top of the Plots pane to navigate plot history.

✅ What success looks like

Console shows the numeric output from mean(), sd(), and summary(). The Plots pane shows a scatter of five points with a dashed orange trend line. If you see a red error message instead, check the troubleshooting section at the end of this guide.

Running code: three ways

Method What runs Shortcut
Run line The line the cursor is on Ctrl/⌘+Enter
Run selection Highlighted text Ctrl/⌘+Enter
Source file Entire script silently Ctrl/⌘+Shift+S

7
Create an R Markdown File
File → New File → R Markdown…

R Markdown (.Rmd) files weave together prose, code, and output into a single reproducible report. Every tutorial in this course is an Rmd file — including this one.

Create your first Rmd

  1. Go to File → New File → R Markdown…
  2. Fill in the dialog:
    • Title: My First Report
    • Author: your name
    • Output Format: HTML (default)
  3. Click OK

RStudio opens a template with a YAML header and some example chunks. The top of the file looks like this:

---
title: "My First Report"
author: "Your Name"
date: "`r Sys.Date()`"
output: html_document
---

Key Rmd elements

⚙️ The three building blocks of an Rmd file

  1. YAML header (between the --- fences) — controls title, author, date, output format
  2. Prose (plain text outside code chunks) — written in Markdown:
    • # Heading 1, ## Heading 2
    • **bold**, *italic*
    • - item for bullet lists
  3. Code chunks (between ```{r} and ```) — R code that runs when you Knit

Add your own chunk

Click where you want a chunk, then use Insert → R or press Ctrl/⌘+Alt+I:

```{r stream-plot}
# Dissolved oxygen versus temperature
temp <- seq(10, 25, by = 1)
DO   <- 14.6 - 0.38 * temp
plot(temp, DO,
     type = "l", lwd = 2, col = "#4a7c5e",
     xlab = "Temperature (°C)", ylab = "DO (mg/L)",
     main = "DO–Temperature Relationship")
```

8
Knit to HTML
Render your Rmd into a shareable report

Click the Knit button (the blue yarn-ball icon) at the top of the Source pane, or press Ctrl/⌘+Shift+K.

RStudio will:

  1. Start a fresh R session (separate from your current one)
  2. Run every code chunk from top to bottom
  3. Weave the output together with your prose
  4. Write an .html file to the same folder as your .Rmd
  5. Open a preview in the Viewer pane

⚠️ Knitting starts from a clean session

The fresh session that Knit uses has no objects from your interactive Console. If your script relies on a variable you created interactively but never saved to the Rmd, knitting will fail with object not found. Everything your Rmd needs must be defined inside a code chunk.

Useful chunk options

Chunk options go inside the {r} header and control how output appears:

```{r my-plot, echo=FALSE, fig.cap="My caption", fig.height=4}`r ''`
# echo=FALSE  — run code but hide the source in the output
# fig.cap     — add a caption below the figure
# fig.height  — set figure height in inches (fig.width also available)
# eval=FALSE  — show code but don't run it
# include=FALSE — run code silently, hide everything

---

<div class="step-header">
<div class="step-num">9</div>
<div>
<div class="step-title">Install Packages</div>
<div class="step-sub">Extend R with community-built tools</div>
</div>
</div>

Base R covers arithmetic, basic statistics, and simple plots. For environmental data science you will need additional packages. Install them once from CRAN:


``` r
# Core packages used throughout EA030
# Run once — you do NOT need to reinstall each session
install.packages(c(
  "tidyverse",    # ggplot2, dplyr, tidyr, readr, and more
  "lme4",         # mixed-effects models
  "lmerTest",     # p-values for lme4
  "car",          # added-variable plots, Anova()
  "MuMIn",        # model selection (AIC, R²)
  "vegan",        # multivariate ecology
  "sf",           # spatial data
  "lubridate",    # dates and times
  "janitor",      # data cleaning utilities
  "here"          # robust relative paths
))

✅ install.packages() vs. library()

install.packages("pkg") — downloads and installs from CRAN. Run once, ever (or when you want a newer version).

library(pkg) — loads an installed package into the current session. Run every session, at the top of every script.

Think of install.packages() as buying a book; library() as taking it off the shelf.

Update packages

Keep packages current with:

update.packages(ask = FALSE)   # update all installed packages

Keyboard Shortcut Reference

These shortcuts will dramatically speed up your workflow. The macOS equivalents replace Ctrl with ⌘ and Alt with ⌥.

Run line / selection
Ctrl+Enter
Knit document
Ctrl+Shift+K
New script
Ctrl+Shift+N
Insert code chunk
Ctrl+Alt+I
Save file
Ctrl+S
Comment/uncomment
Ctrl+Shift+C
Source entire script
Ctrl+Shift+S
Auto-indent selection
Ctrl+I
Find in file
Ctrl+F
Find across project
Ctrl+Shift+F
Clear console
Ctrl+L
Assignment operator (<-)
Alt+-
Pipe operator (|>)
Ctrl+Shift+M
Restart R session
Ctrl+Shift+F10
Focus Source pane
Ctrl+1
Focus Console pane
Ctrl+2

Verify Your Setup

Run the following chunk to confirm all core EA030 packages are installed and print your R version:

# Packages needed for EA030
pkgs_needed <- c("tidyverse", "lme4", "lmerTest", "car", "MuMIn", "here")

installed   <- rownames(installed.packages())
missing     <- setdiff(pkgs_needed, installed)

if (length(missing) == 0) {
  cat("✅ All required packages are installed.\n")
} else {
  cat("❌ Missing packages — run install.packages() for:\n")
  cat(paste(" •", missing), sep = "\n")
}
## ❌ Missing packages — run install.packages() for:
##  • here
cat("\n")
cat("R version:", R.version.string, "\n")
## R version: R version 4.5.2 (2025-10-31)
cat("Platform: ", R.version$platform, "\n")
## Platform:  x86_64-pc-linux-gnu
cat("Date:     ", format(Sys.Date(), "%Y-%m-%d"), "\n")
## Date:      2026-04-14
library(ggplot2)

ggplot(data.frame(x = rnorm(200), y = rnorm(200)), aes(x, y)) +
  geom_point(colour = "#4a7c5e", alpha = 0.55, size = 2) +
  geom_smooth(method = "lm", colour = "#c8832a", se = TRUE,
              fill = "#d4e6da") +
  labs(title    = "Setup verification — ggplot2 is working",
       subtitle = "200 random points with OLS line",
       x = "x", y = "y") +
  theme_minimal(base_size = 13) +
  theme(plot.title    = element_text(family = "serif", face = "bold",
                                     colour = "#1e3a2f"),
        plot.subtitle = element_text(colour = "#7a7a72", size = 10))
A test ggplot. If this renders correctly, ggplot2 (part of the tidyverse) is working.

A test ggplot. If this renders correctly, ggplot2 (part of the tidyverse) is working.


Troubleshooting

Common setup problems and solutions.
Problem Likely cause Fix
RStudio cannot find R on launch R installed after RStudio, or wrong architecture (Mac Intel vs Silicon) Reinstall R matching your OS/chip; relaunch RStudio
Knitting fails with object not found Object created interactively but not defined inside an Rmd chunk Add the object definition inside a chunk in the Rmd
Package install fails with permission denied Installing to a system library that requires admin rights Run RStudio as administrator, or install to a user library: install.packages(‘pkg’, lib = .libPaths()[1])
library(pkg) gives there is no package called 'pkg' Package not yet installed on this machine / R version Run install.packages(‘pkg’) then library(pkg) again
Plot appears blank / grey Graphics device conflict — may happen after package errors Run dev.off() in the Console to reset the graphics device
Console shows only > with no output after running code R is waiting for you to close an incomplete expression — look for + prompt Press Escape in the Console to cancel; then fix the open bracket/quote

🔑 Setup checklist — before your first EA030 analysis

If using RStudio Server (rstudio.pomona.edu):

If using local RStudio Desktop:


What’s next?