Skip to course content
Free R statistics course

Statistical Data Analytics with R

Unit 12.01: Sourced scripts, inline expressions

The analysis lives in scripts. The report cites their objects. No number in the prose is ever typed.

Sourced scripts, inline expressions

The structure that scales is a Quarto document whose setup chunk sources the analysis scripts, and whose prose refers to the resulting objects through inline expressions. Revise the data, re-render, and every figure in every sentence updates together.

echo: false hides the code from readers who want findings while leaving it in the file for anyone checking the work.

The discipline is that the report performs no analysis of its own. If a number is needed in the prose, the script computes and stores it — which also means the number in the text and the number in the table cannot diverge.

This block writes a complete report skeleton and inspects it.

qmd <- c(
  "---",
  "title: Checkout variant B: 7-day retention",
  "date: 2026-07-29",
  "format: html",
  "execute:",
  "  echo: false",
  "  warning: false",
  "---",
  "",
  "

Twenty-four lines with sections for Question, Result and Limitations, 4 inline expressions in the prose, and 0 numbers typed by hand. The setup chunk sources the cleaning and analysis scripts, so the document contains no analysis logic of its own.

The mistake this prevents

The mistake is rendering once and then editing the output. The next render overwrites the edit, and until then the source and the published document disagree.

Takeaway

Put the analysis in sourced scripts and reference their objects with inline expressions. Re-render from scratch before circulating, and never edit the rendered output.