| Title: | Learn R for Clinical Statistics, Interactively |
|---|---|
| Description: | A swirl-style, learn-by-doing course that teaches clinicians and clinical researchers to wrangle, tidy, visualise and analyse clinical data in R. Lessons are interactive 'learnr' tutorials graded by 'gradethis', built on the tidyverse and real-feeling synthetic clinical datasets. |
| Authors: | A. P. S. Munro [aut, cre] |
| Maintainer: | A. P. S. Munro <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.3.3 |
| Built: | 2026-09-22 17:39:06 UTC |
| Source: | https://github.com/apsmunro/r4clinstats |
Diagnoses the things that commonly stop a learner getting started on a managed Windows machine, and optionally fixes them: an out-of-date R, a package library living inside a synced OneDrive folder, no route to the package repositories, and missing packages. It prints a short report.
check_setup(install = interactive())check_setup(install = interactive())
install |
Logical. Offer to install any missing packages. Defaults to
|
Invisibly TRUE if everything needed is present, otherwise FALSE.
## Not run: check_setup() check_setup(install = TRUE) ## End(Not run)## Not run: check_setup() check_setup(install = TRUE) ## End(Not run)
Repeated measurements for the patients cohort: systolic blood pressure and
weight at three visits. Long format, one row per patient * visit * measure.
Built reproducibly (set.seed(2025)) from patients; the generator is in
data-raw/labs.R. SBP falls faster on the active arm, so a trend is there to
be found once the data is pivoted.
labslabs
A data frame with 600 rows and 5 variables:
Patient identifier, matching patients.
Visit number: 0, 1 or 2.
Weeks since baseline: 0, 12 or 24.
"sbp" or "weight".
Measured value.
Synthetic.
Lists the course modules and opens one as an interactive tutorial in your
browser. With no argument it lists the modules and returns you to the
prompt; pass a module id (for example "m3" or 3) to open that one.
learn(module = NULL)learn(module = NULL)
module |
Optional module id, such as |
There is deliberately no numbered pick-list. utils::menu() numbers from 1,
so its numbers could never match module ids that start at m0, and a learner
typing 10 for "m10" would open m9. One way in, learn("m10"), avoids both
that and the separate Selection: mode, which rejects R code.
Invisibly NULL. Called for the side effect of launching a tutorial.
## Not run: learn() # list the modules learn("m3") # open Wrangling I ## End(Not run)## Not run: learn() # list the modules learn("m3") # open Wrangling I ## End(Not run)
A small, deliberately untidy dataset for the cleaning lesson (M6): the same
problems you meet in real intake data. Synthetic and built reproducibly
(set.seed(2027)); the generator is in data-raw/linelist.R. Everything
except weight is stored as text, and the mess is intentional.
linelistlinelist
A data frame with 50 rows and 6 variables:
Patient identifier, e.g. "L01".
The same variable typed inconsistently ("Female", "female", "MALE", ...).
Age as text, including a few non-numeric entries that become NA.
Smoking status in lower case: "never", "former" or "current".
Treatment arm: "Active" or "Placebo".
Weight in kg, with some values missing (NA).
Synthetic.
One year of follow-up for the patients cohort, for the analysis lessons
(M10-M13): treatment response, adverse events, and a time-to-event pair
censored at one year. Built reproducibly (set.seed(2026)) from patients;
the generator is in data-raw/outcomes.R. The signal is planted: response
is likelier on the active arm, and the active arm's event hazard is lower.
Like labs, the table carries no arm or age column on purpose, so the
lessons join back to patients.
outcomesoutcomes
A data frame with 100 rows and 5 variables:
Patient identifier, matching patients.
Treatment response: "Y" or "N".
Any adverse event: "Y" or "N".
Days of event-free follow-up (1-365).
1 if the event occurred at time, 0 if censored at one year.
Synthetic.
A made-up cohort of 100 trial patients, one row each. Built reproducibly
(set.seed(2024)) and containing no real patient data. The generator is in
data-raw/patients.R. Columns are stored as character (not factor) on
purpose, so the early lessons read naturally and M2 can teach factors.
patientspatients
A data frame with 100 rows and 7 variables:
Patient identifier, e.g. "P001".
Age in years (40-88).
"Female" or "Male".
Treatment arm: "Placebo" or "Active".
Smoking status: "Never", "Former" or "Current".
Body-mass index.
Systolic blood pressure (mmHg).
Synthetic.
Copies the course's Quarto report template into your working directory and opens it, ready to complete and render. This is the final exercise of the course (Lesson 14): a real, reproducible analysis report built outside the tutorial sandbox. The template renders as-is; you fill in one analysis chunk at a time.
start_report(path = "trial-report.qmd", completed = FALSE, overwrite = FALSE)start_report(path = "trial-report.qmd", completed = FALSE, overwrite = FALSE)
path |
Where to put the report. Defaults to |
completed |
Logical. |
overwrite |
Logical. Overwrite |
Invisibly, the path to the new file.
## Not run: start_report() # the template, ready to complete start_report(completed = TRUE) # the finished version, to compare ## End(Not run)## Not run: start_report() # the template, ready to complete start_report(completed = TRUE) # the finished version, to compare ## End(Not run)
Creates a local package library and points R at it by writing R_LIBS_USER
to your ~/.Renviron. Use this when check_setup() reports that your
library sits inside OneDrive. Restart R afterwards for it to take effect.
use_local_library( path = file.path(Sys.getenv("LOCALAPPDATA", unset = path.expand("~")), "R", "library") )use_local_library( path = file.path(Sys.getenv("LOCALAPPDATA", unset = path.expand("~")), "R", "library") )
path |
Directory for the local library. Defaults to a folder under
|
Invisibly, the library path.