R.version.string1 Before You Begin: Setup
This page tells you everything you need to do once, before starting the course. Setting up R, RStudio, and the core packages takes about 20-35 minutes, most of it spent waiting for installations to finish (Step 2 alone takes 10-20 minutes, mostly unattended). Steps 3 and 4 are optional and only needed for specific sessions; add ~10-15 minutes if you need them. After that, each session just works.
If your goal is to understand statistical concepts and methods (not to learn R programming), you can skip Parts 1 and 2 and start directly at Part 3: Inference. The statistics begins there. You can still follow the Examples in each session by reading the code output without running it yourself, but you will still need R and the packages installed to run anything interactively.
Every code block below is a command to copy into your RStudio Console, not code that runs automatically when this page is built (that is why each block is marked eval: false). Work through the steps in order from top to bottom - each one builds on the last - and wait for each install to finish (the > prompt returns) before starting the next.
1.1 Step 1: Install R and RStudio
Estimated time: ~5-10 minutes (Setup)
You need two things on your computer:
| Software | What it is | Download |
|---|---|---|
| R (version = 4.2) | The statistical computing language | cran.r-project.org |
| RStudio Desktop | The editor you will use to write and run R code | posit.co/download/rstudio-desktop |
Install R first, then RStudio. On Windows, accept all defaults during installation.
To check your R version, run this in the RStudio Console:
Step 1b: Install Rtools (Windows Only)
Estimated time: ~5 minutes (Setup, Windows only)
Many R packages compile C or Fortran code during installation. Without Rtools, Windows will silently install outdated pre-compiled versions of packages, which can cause version conflicts that break Quarto rendering later.
- Go to cran.r-project.org/bin/windows/Rtools/
- Download and install the version that matches your R version (e.g., Rtools44 for R 4.4, Rtools43 for R 4.3)
- Accept all defaults (no changes needed)
- Restart RStudio after installation
To confirm Rtools is active, run this in the Console; you should see TRUE:
pkgbuild::has_build_tools(debug = TRUE)1.2 Step 2: Install Course Packages (CRAN)
Estimated time: ~10-20 minutes (Setup, mostly unattended)
Copy and paste the block below into your RStudio Console and press Enter. This installs every package used across all sessions in one go. You only need to do this once.
Installing 25+ packages for the first time takes time. R will print a lot of output as it downloads and compiles each package. Do not close RStudio and do not interrupt the process. Just wait until you see the > prompt return in the Console. Go make a coffee.
install.packages(c(
# Quarto rendering essentials (must have current versions)
"knitr",
"rmarkdown",
"xfun",
# Core data wrangling and visualization (used in every session)
"tidyverse",
"patchwork",
# Exploration and summary tables
"skimr",
"janitor",
"gtsummary",
"GGally",
"nhanesA",
# Data import
"readxl",
"palmerpenguins",
# Missing data
"naniar",
"mice",
# Survival analysis
"survival",
"ggsurvfit",
# Regression and modeling
"broom",
"broom.mixed",
"car",
"lme4",
"glmnet",
"parsnip",
"performance",
"pROC",
"AER",
# Causal inference
"dagitty",
"ggdag",
# Inference and testing
"pwr",
# Reproducibility
"reprex"
))# Install Bioconductor packages used in some sessions
if (!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocManager")
## (Omics session removed)
## Bioconductor note: advanced visualization onlyRun install.packages("packagename") individually to see the specific error message. On Windows, restart RStudio and try again; some packages need RTools. On macOS, you may need to install Xcode Command Line Tools first: xcode-select --install in the Terminal.
1.3 Step 3: Install Bioconductor Packages
Estimated time: ~5-10 minutes (Setup, optional)
The Advanced Visualization session optionally uses a Bioconductor package. Install it with:
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install(c(
"GEOquery" # fetching GEO datasets (advanced-visualization session)
))a
During installation you may see:
Update all/some/none? [a/s/n]:
Type a and press Enter. This updates all dependent packages to compatible versions. Pressing n can leave you with mismatched package versions that cause errors later.
Bioconductor packages can take 5-10 minutes to install. If you are not doing the Advanced Visualization session, you can skip this step.
1.4 Step 4: Install TwoSampleMR (GitHub)
Estimated time: ~5 minutes (Setup, optional)
The Mendelian Randomization session uses a package hosted on GitHub:
if (!requireNamespace("remotes", quietly = TRUE))
install.packages("remotes")
remotes::install_github("MRCIEU/TwoSampleMR")This requires an internet connection. If you are not doing the Mendelian Randomization session, you can skip this step.
1.5 Step 5: Verify Your Setup
Estimated time: ~2 minutes (Setup)
Run this block to confirm the core packages are installed. You should see no errors.
core_pkgs <- c(
"knitr", "rmarkdown", "xfun",
"tidyverse", "patchwork", "skimr", "janitor", "gtsummary", "broom",
"survival", "ggsurvfit", "lme4", "broom.mixed", "car",
"glmnet", "performance", "pROC", "mice", "naniar",
"pwr", "dagitty", "ggdag", "GGally", "nhanesA",
"palmerpenguins", "AER", "reprex"
)
missing <- core_pkgs[!sapply(core_pkgs, requireNamespace, quietly = TRUE)]
if (length(missing) == 0) {
message("All core packages are installed. You are ready to start.")
} else {
message("Missing packages: ", paste(missing, collapse = ", "))
message("Run: install.packages(c(", paste0('"', missing, '"', collapse = ", "), "))")
}1.6 Quick Reference: Which Session Uses Which Package
| Package | Sessions |
|---|---|
tidyverse |
All sessions |
survival, broom |
Most Part 3-5 sessions |
janitor |
All Part 2–5 sessions (clean column names) |
gtsummary, skimr |
Descriptive Statistics, Explore Clinical Data |
ggsurvfit |
Survival Analysis |
lme4, broom.mixed, performance |
Mixed Models |
mice, naniar |
Data Imputation; Tidy Data |
glmnet |
Model Building and Diagnostics |
pROC |
Logistic Regression |
car |
Multiple Regression; Model Diagnostics |
GGally |
Correlation and Association |
dagitty, ggdag |
Causal Inference |
AER |
Mendelian Randomization |
TwoSampleMR |
Mendelian Randomization |
pwr |
Power and Sample Size |
GEOquery |
Advanced Visualization |
nhanesA |
Descriptive Statistics; Tidy Data; Explore Clinical Data |
palmerpenguins |
Multiple sessions (practice data) |
knitr, rmarkdown, xfun |
All sessions (Quarto rendering) |
reprex |
Getting Help |