Summary and Schedule
Pomona College HPC Workshop Series
This workshop is part of the Pomona College Research Computing Workshop Series, adapted from R for Reproducible Scientific Analysis by Software Carpentry.
Cluster: sagehen.hpc.pomona.edu Web Portal: OnDemand Support: its-hpc@pomona.edu
R and RStudio are available on Sagehen HPC via
module load r or through the OnDemand portal. Reproducible
analysis practices are essential for HPC research workflows.
Adapted for Pomona College by Andrew Wilson, ITS Research Computing. Licensed under CC-BY 4.0.
an introduction to R for non-programmers using gapminder data
The goal of this lesson is to teach novice programmers to write modular code and best practices for using R for data analysis. R is commonly used in many scientific disciplines for statistical analysis and its array of third-party packages. We find that many scientists who come to Software Carpentry workshops use R and want to learn more. The emphasis of these materials is to give attendees a strong foundation in the fundamentals of R, and to teach best practices for scientific computing: breaking down analyses into modular units, task automation, and encapsulation.
Note that this workshop will focus on teaching the fundamentals of the programming language R, and will not teach statistical analysis.
The lesson contains more material than can be taught in a day. The instructor notes page has some suggested lesson plans suitable for a one or half day workshop.
A variety of third party packages are used throughout this workshop. These are not necessarily the best, nor are they comprehensive, but they are packages we find useful, and have been chosen primarily for their usability.
Prerequisites
Understand that computers store data and instructions (programs, scripts etc.) in files. Files are organised in directories (folders). Know how to access files not in the working directory by specifying the path.
Acknowledgments
Developed by Andrew Wilson, Director of Research Computing and Digital Scholarship at Pomona College, with Andrei Motchenko, who tested, edited and produced screenshots for the workshop series.
| Setup Instructions | Download files required for the lesson | |
| Duration: 00h 00m | 1. Introduction to R and RStudio |
How to find your way around RStudio? How to interact with R? How to manage your environment? How to install packages? |
| Duration: 00h 55m | 2. Project Management With RStudio | How can I manage my projects in R? |
| Duration: 01h 25m | 3. Seeking Help | How can I get help in R? |
| Duration: 01h 45m | 4. Data Structures |
How can I read data in R? What are the basic data types in R? How do I represent categorical information in R? |
| Duration: 02h 40m | 5. Exploring Data Frames | How can I manipulate a data frame? |
| Duration: 03h 10m | 6. Subsetting Data | How can I work with subsets of data in R? |
| Duration: 04h 00m | 7. Control Flow |
How can I make data-dependent choices in R? How can I repeat operations in R? |
| Duration: 05h 05m | 8. Creating Publication-Quality Graphics with ggplot2 | How can I create publication-quality graphics in R? |
| Duration: 06h 25m | 9. Vectorization | How can I operate on all the elements of a vector at once? |
| Duration: 06h 50m | 10. Functions Explained | How can I write a new function in R? |
| Duration: 07h 50m | 11. Writing Data | How can I save plots and data created in R? |
| Duration: 08h 10m | 12. Splitting and Combining Data Frames with plyr | How can I do different calculations on different sets of data? |
| Duration: 09h 10m | 13. Data Frame Manipulation with dplyr | How can I manipulate data frames without repeating myself? |
| Duration: 10h 05m | 14. Data Frame Manipulation with tidyr | How can I change the layout of a data frame? |
| Duration: 10h 50m | 15. Producing Reports With knitr | How can I integrate software and reports? |
| Duration: 12h 05m | 16. Writing Good Software | How can I write software that other people can use? |
| Duration: 12h 20m | Finish |
The actual schedule may vary slightly depending on the topics and exercises chosen by the instructor.
R for Reproducible Scientific Analysis - Setup Guide
This workshop teaches you how to use R and RStudio for reproducible data analysis, focusing on the Gapminder dataset. You have two setup options: use R on Pomona’s Sagehen HPC cluster, or install R locally on your computer.
Option 1: Sagehen HPC (Recommended for Workshop)
Using R on Sagehen is ideal for this workshop because: - Pre-installed software (no installation needed) - Shared Gapminder data files available - Easy access via web browser - Collaborative environment
Access R on Sagehen via OnDemand
Step 1: Log into OnDemand
- Open browser: https://ondemand.hpc.pomona.edu/
- Log in with Pomona credentials (Duo authentication required)
- Click “Interactive Apps” in the top menu
- Select “RStudio Server” (or “RStudio” if available)
Step 2: Request RStudio Session
When prompted, enter: - Number of hours: 2-4 (for workshop) - Memory: 8 GB (minimum) - CPU cores: 2-4 - Click “Launch”
Wait 30-60 seconds for the RStudio window to appear.
Option 2: Local Installation (If You Prefer)
If you prefer R on your personal computer instead of Sagehen HPC:
Install R
Download and install the latest version of R from https://www.r-project.org/:
- Windows: Click “Download R for Windows” → “base” → Download the installer
- Mac: Click “Download R for (Mac)” → Choose your processor type (Intel or Apple Silicon)
-
Linux: Follow distro-specific instructions or use
package manager:
- Ubuntu:
sudo apt install r-base - Fedora:
sudo dnf install R
- Ubuntu:
Install RStudio
Download RStudio Desktop (free version) for your operating system.
RStudio is an IDE that makes R much easier to use.
Workshop Setup Verification
For Sagehen HPC Users
Verify you have access to workshop materials:
R
# Check workshop materials location
list.files("/data/gapminder/")
# Should show: gapminder.txt, continents.csv, or similar
# Check what files are available
dir("/data/gapminder/")
If files exist, you can use Sagehen for the workshop. If not, contact its-hpc@pomona.edu.
Loading Modules on Sagehen HPC
If using Sagehen via terminal (not OnDemand RStudio), load R modules:
BASH
# SSH into Sagehen
ssh <myusername>@sagehen.hpc.pomona.edu
# Check available R versions
module avail R
# Shows: r/4.2.2, r/4.2.3, r/4.4.1, r/4.5.1 (D)
# Load R (module names are lowercase)
module load r/4.5.1 # (or just `module load r` for the default)
# Start R
R
# In R console
> R.version
# Verifies it works
Installing Packages on Sagehen HPC
For Sagehen users, install workshop packages in user space:
R
# In R console (started via `module load r`)
# Set user library path
dir.create(Sys.getenv("HOME"), ".R/library", recursive = TRUE)
.libPaths(file.path(Sys.getenv("HOME"), ".R/library"))
# Install ggplot2 (for visualization)
install.packages("ggplot2", repos = "http://cran.r-project.org")
# Answer 'yes' to "Create a personal library in..." if prompted
# Install tidyverse (collection of useful packages)
install.packages("tidyverse", repos = "http://cran.r-project.org")
# Verify installation
library(ggplot2)
library(dplyr)
# Should load without errors
Downloading Gapminder Data
Via Sagehen HPC (OnDemand RStudio)
The Gapminder data is already available at:
R
# Read Gapminder data
gapminder <- read.csv("/data/gapminder/gapminder.csv")
# View first few rows
head(gapminder)
# Check dimensions
dim(gapminder)
# Should show: 1704 rows x 6 columns
If the file path doesn’t work, download it from:
R
# Download from official source
url <- "https://raw.githubusercontent.com/swcarpentry/r-novice-gapminder/gh-pages/data/gapminder_data.csv"
gapminder <- read.csv(url)
Via Local R Installation
Download the Gapminder data file:
R
# In RStudio console
url <- "https://raw.githubusercontent.com/swcarpentry/r-novice-gapminder/gh-pages/data/gapminder_data.csv"
download.file(url, "gapminder_data.csv")
# Read it into R
gapminder <- read.csv("gapminder_data.csv")
# Verify
head(gapminder)
dim(gapminder)
Alternatively, download the CSV directly and open in RStudio.
RStudio Configuration
Default Settings (Usually Fine)
RStudio works well with default settings. Optional improvements:
Tools → Global Options: - General: Uncheck “Save workspace to .RData” - Code → Editing: Enable “Soft-wrap R source files” (easier reading) - Appearance: Choose your preferred theme (light/dark) - Pane Layout: Default layout works; customize if preferred
Troubleshooting
“Packages won’t install on Sagehen HPC”
If you get permission errors:
- Create user library directory:
R
dir.create(file.path(Sys.getenv("HOME"), ".R"), showWarnings = FALSE)
dir.create(file.path(Sys.getenv("HOME"), ".R/library"), showWarnings = FALSE)
- Set library path before installing:
R
.libPaths(file.path(Sys.getenv("HOME"), ".R/library"))
install.packages("ggplot2")
“Can’t find Gapminder data”
- Check file path:
list.files("/data/gapminder/")orlist.files(".") - Download from GitHub (command shown above)
- Contact its-hpc@pomona.edu if /data/gapminder not available
“RStudio won’t start on OnDemand”
- Check internet connection
- Try refreshing the page
- Check available compute resources (may need to wait)
- Contact its-hpc@pomona.edu
Before the Workshop
Verify your setup is working:
For Sagehen users: - [ ] Can log into OnDemand (https://ondemand.hpc.pomona.edu) - [ ] Can launch
RStudio from Interactive Apps - [ ] Can type R.version in
console and see R 4.x - [ ] Can see /data/gapminder/ data
files (or download them) - [ ] Can load ggplot2 package
For local R users: - [ ] R installed from https://www.r-project.org/ - [ ] RStudio Desktop
installed - [ ] Can open RStudio and see R console - [ ] Can download
Gapminder CSV file - [ ] Can read CSV with
read.csv("gapminder_data.csv")
Getting Help
- Sagehen issues: Email its-hpc@pomona.edu
- R/RStudio questions: Office hours (see workshop info)
- Data questions: Ask instructor during workshop
-
Debugging: Use
?function_namein R to see help