Common Code 01 — Libraries

Every package used in this course, grouped by purpose

packages
setup

Every R package used in the course, grouped by purpose, with a one-time install script so you never re-run install.packages() by accident.

Author

Bill Perry

Published

July 5, 2026

Package Reference

This page lists every R package used in this course, organised from beginner essentials through to advanced methods. Install each group once using the code blocks below — you only ever need to run install.packages() one time per machine. After that, load only the packages you need for a given session with library().

⬇️ Download the full install script — copy it into your scripts/ folder and run it once: install_packages.R

⚠️ Watch out! Never put install.packages() inside a script you run regularly. Installation only needs to happen once. Putting it in a regular script re-downloads the package every time, which is slow and can break things.


1 · Core Workflow

These are the packages you will load in almost every analysis. Install them first.

install.packages("tidyverse")    # dplyr, ggplot2, tidyr, purrr, readr, stringr, forcats
install.packages("lubridate")    # working with dates and times
install.packages("readxl")       # read Excel (.xlsx / .xls) files into R
install.packages("writexl")      # write data frames back out to Excel
install.packages("janitor")      # clean messy column names and tabulate data
install.packages("skimr")        # quick, readable summary statistics
install.packages("glue")         # paste strings together cleanly with {variable} syntax
install.packages("devtools")     # install packages from GitHub and other sources
install.packages("remotes")      # lighter alternative to devtools for GitHub installs

What you load each session

library(tidyverse)   # loads dplyr, ggplot2, tidyr, readr, purrr, stringr, forcats
library(lubridate)   # date / time helpers
library(readxl)      # read Excel files
library(janitor)     # clean_names() and tabyl()
library(skimr)       # skim() for quick summaries

2 · Plotting

Core plotting extensions

ggplot2 is already part of tidyverse. These packages add to it.

install.packages("patchwork")    # combine multiple ggplot panels into one figure
install.packages("scales")       # fine-grained control of axis breaks, labels, and colours
install.packages("ggthemes")     # extra complete themes (Economist, FiveThirtyEight, etc.)
install.packages("ggridges")     # ridge / joy plots for overlapping distributions
install.packages("ggpubr")       # publication-ready figures; add p-value brackets to plots

Colour and style

install.packages("viridis")      # perceptually uniform, colour-blind-safe palettes
install.packages("ggtext")       # render markdown / HTML inside plot text and labels
install.packages("showtext")     # use Google Fonts and custom fonts in ggplot
install.packages("ragg")         # fast, high-quality PNG/TIFF rendering device

Interactive and animated plots

install.packages("plotly")       # turn any ggplot into an interactive HTML figure
install.packages("ggiraph")      # add tooltips and click interactions to ggplot geoms
install.packages("gganimate")    # animate ggplots (requires gifski or av for output)
install.packages("gifski")       # render gganimate output as GIF
install.packages("av")           # render gganimate output as MP4 video

Saving and previewing

install.packages("ggview")       # preview a plot at exact export dimensions before saving

3 · Tables

For getting results out of R and into Word documents or HTML pages.

install.packages("flextable")    # publication tables that export cleanly to Word and PowerPoint
install.packages("gt")           # grammar-of-tables: highly customisable HTML/PDF tables
install.packages("knitr")        # kable() for simple tables inside Quarto documents
install.packages("kableExtra")   # extend kable() with styling, spanning headers, and more
install.packages("tinytable")    # minimal, fast tables designed for Quarto
install.packages("huxtable")     # tables that export to Word, LaTeX, and HTML
install.packages("officer")      # read and write Word and PowerPoint files from R
install.packages("webshot2")     # screenshot HTML widgets to PNG (required by some table packages)
install.packages("pandoc")       # R interface to the pandoc document converter

4 · Data Import and Export

install.packages("readxl")       # (already in Core — listed again for reference)
install.packages("writexl")      # write to Excel without Java or other dependencies
install.packages("arrow")        # read/write Parquet and Feather files; very fast large data
install.packages("duckdb")       # run SQL queries on data frames and Parquet files directly in R

5 · Descriptive Statistics

First steps when you have data in hand.

install.packages("skimr")        # (already in Core) skim() gives a fast distributional overview
install.packages("psych")        # describe(), pairs.panels(), alpha() for scale reliability
install.packages("Hmisc")        # rcorr(), and a large collection of utility functions
install.packages("moments")      # skewness() and kurtosis()
install.packages("FSA")          # Dunn test, length-frequency analysis, age-bias plots

6 · Statistical Tests

General tests

install.packages("car")          # Anova() with Type II/III SS; leveneTest(); vif()
install.packages("broom")        # tidy(), glance(), augment() — model output as tibbles
install.packages("emmeans")      # estimated marginal means and pairwise contrasts
install.packages("multcompView") # compact letter display for pairwise comparisons
                                 # NOTE: can mask some dplyr functions — load with care
install.packages("Rmisc")        # summarySE() for mean ± SE tables
install.packages("coin")         # exact and permutation-based versions of common tests
install.packages("rcompanion")   # effect sizes and non-parametric summaries
install.packages("pwr")          # power analysis for t-tests, ANOVA, correlation, chi-square
install.packages("perm")         # exact permutation tests

7 · ANOVA and Linear Models

install.packages("car")          # (already listed) Type II/III ANOVA; assumption checks
install.packages("afex")         # aov_ez() for factorial ANOVA; handles repeated measures cleanly
install.packages("emmeans")      # (already listed) pairwise comparisons after ANOVA
install.packages("multcompView") # (already listed) letter displays for post-hoc tests
install.packages("relaimpo")     # relative importance of predictors in multiple regression
install.packages("broom")        # (already listed) tidy model output

8 · Mixed-Effects Models

For nested, repeated-measures, or hierarchical data structures.

install.packages("lme4")         # lmer() and glmer() — the core mixed-model engine in R
install.packages("lmerTest")     # adds p-values to lmer() output (Satterthwaite degrees of freedom)
install.packages("broom.mixed")  # tidy() and glance() for lme4 and nlme model objects
install.packages("afex")         # (already listed) mixed_() wrapper for factorial mixed models
install.packages("emmeans")      # (already listed) contrasts and marginal means for mixed models
install.packages("performance")  # R², ICC, and check_model() diagnostic plots
install.packages("see")          # visualisation companion to performance
install.packages("sjPlot")       # plot_model() for fixed/random effects; tab_model() tables

9 · Generalised Linear Models

For count data, proportions, binary outcomes, and zero-inflated responses.

install.packages("car")          # (already listed) Anova() works for GLMs too
install.packages("broom")        # (already listed) tidy GLM output
install.packages("emmeans")      # (already listed) marginal means on the response scale
install.packages("pscl")         # zero-inflated Poisson and negative-binomial GLMs
install.packages("DHARMa")       # residual diagnostics for GLMs and GLMMs via simulation
install.packages("ResourceSelection") # Hosmer-Lemeshow goodness-of-fit for logistic regression
install.packages("faraway")      # datasets and functions from Faraway's GLM textbook

10 · Model Visualisation and Comparison

install.packages("dotwhisker")   # dot-and-whisker coefficient plots for regression models
install.packages("ggfortify")    # autoplot() for lm, glm, PCA, time-series objects
install.packages("interactions") # interact_plot() and cat_plot() for interaction effects
install.packages("performance")  # (already listed) compare model fit, check assumptions
install.packages("see")          # (already listed) plots for performance outputs
install.packages("sensemakr")    # sensitivity analysis for unmeasured confounding

11 · Correlation and Multivariate

install.packages("corrplot")     # visualise correlation matrices as coloured grids or circles
install.packages("GGally")       # ggpairs() scatterplot matrix; ggcoef() coefficient plots
install.packages("psych")        # (already listed) polychoric / tetrachoric correlations
install.packages("FactoMineR")   # PCA, CA, MCA — full-featured multivariate methods
install.packages("factoextra")   # ggplot-based biplots and scree plots for FactoMineR / prcomp

12 · Community Ecology and Multivariate Ordination

install.packages("vegan")        # NMDS, PERMANOVA (adonis2), diversity indices, ordination
install.packages("RVAideMemoire") # pairwise PERMANOVA and other ecology helpers
install.packages("pairwiseAdonis") # pairwise adonis2 (CRAN version)

The GitHub development version of pairwiseAdonis is more up to date:

devtools::install_github("pmartinezarbizu/pairwiseAdonis/pairwiseAdonis")

13 · Maps and Spatial Data

install.packages("sf")            # simple features: the standard for vector spatial data in R
install.packages("tigris")        # download US Census TIGER shapefiles (states, counties, roads)
install.packages("rnaturalearth") # world country, coastline, and graticule shapefiles
install.packages("osmdata")       # download OpenStreetMap features (roads, buildings, waterways)
install.packages("ggfx")          # blur, shadow, and glow effects on ggplot layers

For 3D terrain rendering:

install.packages(c("rayshader", "elevatr", "raster"))
# rayshader  — render elevation data as 3D maps and raytraced scenes
# elevatr    — download elevation rasters from AWS or OpenTopography
# raster     — raster grid operations (legacy package; terra is the modern replacement)

14 · Teaching Datasets

Clean, well-documented datasets used in examples throughout the course.

install.packages("palmerpenguins") # Palmer Archipelago penguin data — a tidy alternative to iris
install.packages("nycflights13")   # 336,776 flights departing New York City in 2013
install.packages("Lahman")         # Sean Lahman's complete baseball statistics database
install.packages("babynames")      # US baby name counts and proportions, 1880–2017
install.packages("repurrrsive")    # nested list datasets for learning purrr and iteration

15 · Reporting and Workflow

install.packages("htmlwidgets")  # embed interactive HTML widgets in Quarto documents
install.packages("htmltools")    # build and manipulate HTML output from R

Full install script

The block below installs everything in one go. Paste it into the Console (not a script) and run it once. Expect this to take 10–20 minutes the first time.

# ── CORE ──────────────────────────────────────────────────────────────────────
install.packages(c(
  "tidyverse", "lubridate", "readxl", "writexl",
  "janitor", "skimr", "glue", "devtools", "remotes"
))

# ── PLOTTING ──────────────────────────────────────────────────────────────────
install.packages(c(
  "patchwork", "scales", "ggthemes", "ggridges", "ggpubr",
  "viridis", "ggtext", "showtext", "ragg",
  "plotly", "ggiraph", "gganimate", "gifski", "av",
  "ggview", "camcorder", "ggThemeAssist", "styler"
))

# ── TABLES ────────────────────────────────────────────────────────────────────
install.packages(c(
  "flextable", "gt", "knitr", "kableExtra",
  "tinytable", "huxtable", "officer", "webshot2", "pandoc"
))

# ── DATA ──────────────────────────────────────────────────────────────────────
install.packages(c("arrow", "duckdb"))

# ── DESCRIPTIVE STATS ─────────────────────────────────────────────────────────
install.packages(c("psych", "Hmisc", "moments", "FSA"))

# ── STATISTICAL TESTS ─────────────────────────────────────────────────────────
install.packages(c(
  "car", "broom", "emmeans", "multcompView",
  "Rmisc", "coin", "rcompanion", "pwr", "perm"
))

# ── ANOVA & LINEAR MODELS ─────────────────────────────────────────────────────
install.packages(c("afex", "relaimpo"))

# ── MIXED MODELS ──────────────────────────────────────────────────────────────
install.packages(c(
  "lme4", "lmerTest", "broom.mixed",
  "performance", "see", "sjPlot"
))

# ── GLMS ──────────────────────────────────────────────────────────────────────
install.packages(c(
  "pscl", "DHARMa", "ResourceSelection", "faraway"
))

# ── MODEL VISUALISATION ───────────────────────────────────────────────────────
install.packages(c(
  "dotwhisker", "ggfortify", "interactions", "sensemakr"
))

# ── MULTIVARIATE ──────────────────────────────────────────────────────────────
install.packages(c(
  "corrplot", "GGally", "FactoMineR", "factoextra",
  "vegan", "RVAideMemoire", "pairwiseAdonis"
))
devtools::install_github("pmartinezarbizu/pairwiseAdonis/pairwiseAdonis")

# ── MAPS ──────────────────────────────────────────────────────────────────────
install.packages(c(
  "sf", "tigris", "rnaturalearth", "osmdata", "ggfx",
  "rayshader", "elevatr", "raster"
))

# ── TEACHING DATASETS ─────────────────────────────────────────────────────────
install.packages(c(
  "palmerpenguins", "nycflights13", "Lahman", "babynames", "repurrrsive"
))

# ── REPORTING ─────────────────────────────────────────────────────────────────
install.packages(c("htmlwidgets", "htmltools"))

End of Common Code 01 — Libraries. Next: Common Code 02 — Reading and writing files.