R Programming

From first object to installed package

12 lessons Beginner to intermediate ~24 hours Exercises with solutions

R is a small language with a large surface area. Most people learn enough of it to get a result and then plateau, carrying habits that work fine on a 200-row dataset and fall apart on a study database. This course is designed to get past that plateau: you learn what R objects actually are, how the tidyverse verbs compose, and how to package your work so someone else can run it two years from now.

Who this is for

  • SAS programmers who need R for a study, a sponsor requirement or a career move
  • Statisticians who write analysis code but have never written a function
  • Analysts who “know dplyr” and want to understand what it is doing
  • Anyone who has been handed a 900-line script and asked to maintain it

No prior R experience is assumed. Prior programming experience in any language — SAS, SQL, Python, VBA — will make the first three lessons go faster.

What you will be able to do

By the end of the course you can read messy source data, reshape it into the form an analysis needs, write tested functions to do it, and ship the whole thing as a version-controlled package that installs cleanly on a colleague’s machine.

Course outline

# Lesson You will learn
1 R and RStudio setup Installing R, RStudio, projects, renv, sane global options
2 Objects and data types Atomic types, coercion, NA, attributes, copy-on-modify
3 Vectors, lists, matrices, data frames Subsetting, recycling, tibbles vs data.frames
4 Importing SAS, CSV and Excel files haven, readr, readxl, encoding, labels, type problems
5 Data manipulation with dplyr The six verbs, grouping, joins, window functions
6 Reshaping with tidyr Pivoting, nesting, separating, completing, rectangling
7 Dates, strings and factors lubridate, stringr, forcats, partial dates, ISO 8601
8 Functions and tidy evaluation Writing functions, { }, .data, purrr
9 Error handling and debugging Conditions, tryCatch, browser(), traceback(), cli
10 Testing with testthat Unit tests, expectations, fixtures, snapshots, coverage
11 Package development usethis, devtools, roxygen2, NAMESPACE, R CMD check
12 Git and GitHub Commits, branches, pull requests, CI, code review

How to work through it

Lessons 1–3 are foundations and should be done in order. Lessons 4–7 are the day-to-day data work and can be skimmed if you already use the tidyverse fluently. Lessons 8–12 are where most self-taught R users have gaps, and are the ones that pay off most in a team setting.

Every lesson follows the same shape: objectives, worked explanation with runnable code, common mistakes, exercises, and a recap. Code blocks are shown but not executed when the site is built, so the output shown in comments is the output you should expect to see.

NotePackage versions

For new training environments in 2026, install the current R 4.6.x release unless your project validation requires an older version. Examples assume R ≥ 4.4, dplyr ≥ 1.2, tidyr ≥ 1.3.2, haven ≥ 2.5.5, readr ≥ 2.2, testthat ≥ 3.3 and renv ≥ 1.2. Where a function’s behaviour changed across recent versions — .by, join_by(), across(), reframe(), the native pipe — the lesson says so explicitly.

For validated study work, follow the approved R version and freeze exact package versions with renv; do not upgrade an active analysis simply because a newer training setup exists.

Start with R and RStudio setup.

Back to top