library(dplyr)
library(ggplot2)
library(readr)
library(tidyr)
cat("R version: ", R.version.string, "\n")
cat("dplyr: ", as.character(packageVersion("dplyr")), "\n")
cat("ggplot2: ", as.character(packageVersion("ggplot2")), "\n")
cat("readr: ", as.character(packageVersion("readr")), "\n")
cat("tidyr: ", as.character(packageVersion("tidyr")), "\n")
# The |> pipe needs R 4.1 or newer. If this prints 3 numbers, you are set.
c(1, 4, 9) |> sqrt()Module 0 · Getting Set Up
Self-paced · do this before Module 1
This module will help you install the softwares necessary for the workshop series. It takes about 30 minutes, and will enable you to following along with the live coding session during the workshop.
When you have completed everything in the checklist at the bottom, you are all ready for the workshop series.
What you are installing, and why
Two things you need to install:
| What it is | |
|---|---|
| R | The language itself. Does the actual computing. On its own, it is a bare window. |
| RStudio | The workbench you sit at to write R. Editor, plots, files, help — all in one place. |
You install R first. RStudio looks for R when it starts up; if R is not there yet, RStudio will not find it.
Install R & RStudio
Step 1 — Install R
Go to the R Project download page and pick your system:
- Windows — click Download R for Windows → base → Download R-x.x.x for Windows. Run the installer and accept the defaults.
- macOS — click Download R for macOS, then pick the
.pkgthat matches your chip. If your Mac is from 2020 or later it is almost certainly Apple silicon (arm64); older Intel Macs use the other one. If you install the wrong one R will not start, so check: Apple menu → About This Mac. - Linux — follow the distribution-specific instructions on that page.
Step 2 — Install RStudio
Go to the RStudio Desktop download page and install the free version for your system. Accept the defaults.
Step 3 — Open RStudio and find your way around
Open RStudio — not R. (On your machine there will be an application called plain “R” too. You will not use it. If you see a plain white window with a > and nothing else, you opened the wrong one.)
You will see four panes. Only two matter today:
| Pane | Where | What it is for |
|---|---|---|
| Console | bottom-left | Where code runs. Type here for one-off, throwaway commands. |
| Editor | top-left | Where code is saved. Write your script here. This is the one that matters. |
| Environment | top-right | Lists the objects you have created. |
| Files / Plots / Help | bottom-right | File browser, your plots, and documentation. |
Write code in the Editor using R script, not the Console. Run code on the current line with Ctrl+Enter (Cmd+Enter on macOS).
Code in the Editor can be saved, re-run and fixed. Code typed into the Console vanishes when you close RStudio, and nothing is more demoralising than losing a working analysis because it only ever existed in the Console.
Many hospital and university machines block software installation. You can use Posit Cloud to run RStudio entirely in your browser.
All you need is a modern web browser and internet access.
- Go to posit.cloud and create a free account.
- Click New Project → New RStudio Project.
You now have RStudio in a browser tab. It looks and behaves like the desktop version, and everything in every module works there. The free tier is generous enough for this workshop.
The one difference: your files live in the cloud project rather than on your laptop. To get a data file in, use the Upload button in the Files pane (bottom-right).
Setting R project
R needs to know where on your computer you are working from, so that you can load your data files and save results in the specific location you want. When you create a new R project, you basically tell RStudio that we are always starting at a specific folder in our computer.
In RStudio: File → New Project → New Directory → New Project. Name it r-workshop, choose somewhere you will find it again (Desktop or Documents), and click Create Project.
Then make two folders inside it. In the Files pane (bottom-right), click New Folder twice and create:
r-workshop/
├── r-workshop.Rproj <- created for you; double-click this to open the project
├── data/ <- the workshop datasets go here
└── output/ <- things you save: plots, cleaned data
Opening the project (double-click the .Rproj file) sets R’s working directory to that folder. Which means that from then on, this works:
read_csv("data/abcd-synthetic.csv")instead of this:
read_csv("C:/Users/YourName/Desktop/stuff/r workshop v2 FINAL/data/abcd-synthetic.csv")The short version is called a relative path — relative to the project folder. It keeps working when you move the folder, rename your laptop, or send the project to a colleague. The long one breaks the moment anything changes.
setwd() in older tutorials
setwd("C:/Users/...") sets the working directory by hand. Avoid it. It hard-codes a path that exists only on your computer, so the script breaks for everyone else and future you when you move the folder.
The better way is to create and opening an RStudio Project.
Download dummy data
Download abcd-synthetic.csv and put it in the data/ folder you just made.
This is a synthetic dataset, containing no real participant data, that we will use for Module 1 to familiarize ourselves with the basics of R programming.
It is deliberately shaped like an ABCD longitudinal release: one row per participant per visit, with realistic gaps where measurements are missing. For simplicity, we have only a few measures per participant-event with names that are easy to understand.
Install R packages
A package is a collection of functions, data, and documentation that are designed for a single or multiple tasks.
R comes with a lot of built in packages, so we do not need to install anything to access their functions. But the tools we will learn come from packages not shipped with R, so we need to install them once.
A function is a reusable piece of code written to carry out a specific task.
It helps you avoid rewriting the same code multiple times.
- Core Purpose: Automates repetitive tasks and organizes code.
- Inputs & Outputs: Takes inputs called arguments, processes them, and returns a result.
- Built-in Functions: R comes with thousands of ready-to-use functions like mean(), sum(), and plot().
- Custom Functions: You can write your own functions using the function() keyword. We do this in the Module 2 functions deep-dive.
In the Console (bottom-left), paste this and press Enter:
install.packages(c("dplyr", "ggplot2", "readr", "tidyr"))This takes a few minutes and prints a great deal of scrolling text. That is normal. Some warnings in that output are also normal.
These four packages are all part of the tidyverse, a family of R packages that share a common style. You can install all of it at once with install.packages("tidyverse"), and many tutorials do. We install the four we actually use, and load them one by one, so that you learn which package each function comes from rather than treating it all as one magic blob.
Installing is a one-time step. Loading, which you do in every new session, is a different thing — that is library(), and Module 1 covers it.
Check that it worked
Paste this whole block into the Console. It loads each package and prints what you have.
You should see version numbers and then three numbers.
R version: R version 4.5.2 (2025-10-31)
dplyr: 1.2.1
ggplot2: 4.0.3
readr: 2.2.0
tidyr: 1.3.2 Your versions will not match mine exactly — anything recent is fine.
An error on c(1, 4, 9) |> sqrt() means your R is older than 4.1 and does not have the |> pipe, which we use throughout the workshop. Go back to Step 1 and install the current version of R. Installing a new R does not delete the old one, and RStudio will pick up the newer one.
This means the install did not finish, usually because it was interrupted or the package name was mistyped. Re-run the install.packages() line above and watch the tail of the output for a line saying which package failed and why.
On Windows, if it asks “Do you want to install from sources the packages which need compilation?”, answer no.
Checklist
Before Module 1 on Sep 10, 2026:
Stuck on any of these? Email us before the session rather than during it — Andrew Moore (ajm9311@ou.edu) or Billu Das (biplabendu.das@gmail.com) — and we will sort it out in advance.
Once the boxes are ticked, you are ready for Module 1 →
Optional: get a head start
These three chapters from the R for Data Science book introduce most of the topics we will cover in Modules 1 and 2.
- Basics — this chapter covers a few basics of programming in R.
- Data Transformation using dplyr — this chapter introduces the various
dplyrfunctions that are used to transform / clean data tables. - Data Visualization using ggplot2 — this chapter covers the philosophy and syntax of using ggplot to create data visualization in R.