Prof. Marc Los Huertos • Pomona College
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.
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/ |
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.
✅ 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.
Pomona College RStudio Server rstudio.pomona.edu
⚠️ 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.
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.
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)
To bring a data file (CSV, Excel, etc.) from your computer onto the server:
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")
To download a file (e.g., your knitted HTML report) back to your computer:
To download an entire folder as a .zip:
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.
| 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 |
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.
Go to https://cran.r-project.org and select your operating system. Follow the tab for your platform below.
Windows
.exe installer — accept all
defaultsC:\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
arm64 .pkgx86_64
.pkg.pkg and follow the installation prompts
(requires admin password)/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.
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)".
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.
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 <- 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">></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).
A few settings will save you hours of debugging. Go to Tools → Global Options and make these changes:
📌 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.
|> (requires R ≥
4.1) → ☑ Checked (optional but modern)Choose a theme and font size that you are comfortable reading for hours. Popular choices:
Click Apply → OK when done.
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").
EA030 and choose where to save
itYou 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.
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.
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.
| 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 |
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.
My First ReportRStudio 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
---
⚙️ The three building blocks of an Rmd file
--- fences) —
controls title, author, date, output format# Heading 1, ## Heading 2**bold**, *italic*- item for bullet lists```{r} and
```) — R code that runs when you KnitClick 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")
```
Click the Knit button (the blue yarn-ball icon) at the top of the Source pane, or press Ctrl/⌘+Shift+K.
RStudio will:
.html file to the same folder as your
.Rmd⚠️ 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.
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.
Keep packages current with:
update.packages(ask = FALSE) # update all installed packages
These shortcuts will dramatically speed up your workflow. The macOS equivalents replace Ctrl with ⌘ and Alt with ⌥.
<-)
|>)
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.
| 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 |
If using RStudio Server (rstudio.pomona.edu):
rstudio.pomona.edu with Pomona credentials
EA030/ folder created in home directory with
data/, reports/, output/
subfolders
If using local RStudio Desktop:
tidyverse, lme4,
car, MuMIn, here
here, and naming
conventionsreadr and janitor