Learn R for clinical statistics, interactively. A swirl-style, learn-by-doing
course for clinicians and clinical researchers: type real code against
real-feeling synthetic clinical data and get immediate, kind feedback. Lessons
are learnr tutorials graded by
gradethis.
All fifteen modules (0–14) are built and runnable (M0–M5 are the MVP).
filter, count, arrange, select, the pipe |>), adapted from the prototype.mutate, group_by + summarise).pivot_wider/pivot_longer, left_join).read_csv/here, recoding, fixing types, missing values).finalfit).broom).lm, baseline adjustment, logistic glm, odds ratios).start_report() and rendered for real).patients, labs, outcomes and linelist (synthetic, reproducible).learn(), check_setup(), use_local_library(), start_report().tests/ that runs every tutorial solution and locks the datasets.The curriculum is complete: foundations, real data, analysis, and reporting.
From the package root, in R:
source("data-raw/patients.R") # writes data/patients.rda
source("data-raw/labs.R") # writes data/labs.rda (run after patients.R)
source("data-raw/outcomes.R") # writes data/outcomes.rda (run after patients.R)
source("data-raw/linelist.R") # writes data/linelist.rda
devtools::document() # regenerate NAMESPACE and man/ from the roxygen comments
devtools::install(dependencies = TRUE) # install locally, with the course packages
devtools::test() # run the harness
gradethis is not on CRAN. It installs from Posit's R-universe; check_setup() handles this, or install it directly:
install.packages("gradethis",
repos = c("https://rstudio.r-universe.dev", getOption("repos")))
The landing page, install guide and browser taster are a pkgdown
site. Build it locally to preview:
install.packages("pkgdown")
pkgdown::build_site()
On every push to master, .github/workflows/pkgdown.yaml rebuilds the site and publishes it to
GitHub Pages at https://apsmunro.github.io/r4clinstats/. Enable Pages once in the repository
settings, serving from the gh-pages branch.
install.packages("r4clinstats",
repos = c("https://apsmunro.r-universe.dev",
CRAN = "https://cloud.r-project.org"),
dependencies = TRUE)
library(r4clinstats)
check_setup() # confirm the install, and fix anything still missing
learn() # list the lessons
learn("m0") # start at the beginning
dependencies = TRUE matters: the packages the tutorials run on (the
tidyverse, finalfit, broom and the rest) are in Suggests, which a plain
install skips. They are in Suggests deliberately, so that a missing
gradethis cannot stop library(r4clinstats) from loading and taking you to
check_setup().
gradethis is fetched separately by check_setup(), from the rstudio
R-universe. It is deliberately not named in the repos above: that universe
also carries development builds of learnr and rmarkdown, and
install.packages() takes the highest version it can see rather than the
first repository listed, so naming it there would quietly put every learner on
an unreleased build of the engine the lessons run on.
Installing from apsmunro.r-universe.dev
rather than with remotes::install_github() keeps learners clear of GitHub's
anonymous API limit of 60 requests an hour per network address, which a shared
hospital or university connection exhausts quickly when a group installs
together.
The full walkthrough is the Get started guide.
MIT. The bundled datasets are synthetic and contain no real patient data.