Memra

Reproducible, re-runnable, auditable

◈ 8 cards

A script re-runs January's whole workflow on February's file by changing one line. RStudio has four panes — Source, Console, Environment/History, Files/Plots/Packages/Help; sales <- 1200 creates an object that appears in Environment.

The argument for a script

In Module 6 you cleaned Maple & Birch's January orders: trimmed the province codes, converted the text amounts, dropped the duplicate, added the HST column, filtered to amounts over 500, and built the province pivot. Twenty minutes of clicks. February's file arrives. The clicks start again — and if you forget one, nobody will know, because a spreadsheet keeps the result of each step and not the step itself.

A script is the list of steps, written down, in a language the computer runs. The February workflow is the January script with its first line changed:

orders <- read.csv("orders_feb.csv")

Everything below that line runs unchanged. That is the whole case for R, and it has three names:

  • Reproducible — the same script on the same file gives the same answer, on any machine, next year.
  • Re-runnable — next month's file is one edit, not twenty minutes.
  • Auditable — a reviewer reads the steps; a spreadsheet reviewer reverse-engineers them from formulas.

The F2025 student reviews call Modules 9–13 "the cliff". The learners who fall are the ones who treat R as a calculator with worse buttons. Hold on to the reason: the script is the deliverable.

Worked example — the four panes

Open RStudio and the window is four panes:

  • Source (top left) — the script file you are writing. Nothing here runs until you send it to the console.
  • Console (bottom left) — where R runs. The prompt is >. Type here and press Enter, or send a line from Source with Ctrl+Enter (Cmd+Enter on a Mac).
  • Environment / History (top right) — the objects that currently exist, with their values, and every command run so far.
  • Files / Plots / Packages / Help (bottom right) — the working folder, the charts, the installed packages, and the help page ?mean opens.

Type in the console:

> sales <- 1200
> sales
[1] 1200
> sales * 1.13
[1] 1356

<- is the assignment operator: put 1200 into an object named sales. (An = works too; <- is what every R book and error message uses.) The moment it runs, sales appears in the Environment pane with its value. Typing the name alone prints it; sales * 1.13 prints the HST-inclusive figure without changing sales.

Two rules the console enforces. Case matters: Sales is not sales:

> Sales
Error: object 'Sales' not found

And a # starts a comment — R ignores the rest of the line, which is where the script says why. A script with no comments is a spreadsheet with no headers.

The + prompt

Type sales * (1 + 0.13 with the bracket unclosed and press Enter. The prompt changes from > to +: R is waiting for the rest of the expression — the closing bracket or quote. It is not computing, and the line has not run. Press Esc to abandon it and get > back.

Type an assignment with its comment, then tour the panes

Type the commented assignment and the multiplication. The questions cover the + prompt, case, and which pane shows what.

CRISP-DM: a script is the deployment → produce final report artefact of every phase — the record of what was done.

panewherewhat lives thereSourcetop leftthe script file; Ctrl+Entersends a line to the consoleConsolebottom leftwhere R runs; the > prompt;output and errorsEnvironment / Historytop rightevery object that exists,with its value; everycommand runFiles / Plots / Packages /Helpbottom rightthe working folder; charts;installed packages; ?meansales <- 1200 in the Console puts sales in Environment; the Source file is unchanged until you typethere.
The four panes. Write in Source, run in Console, watch objects appear in Environment, read help and plots at bottom right.
NORMAL ~/memra/learn/afm-112/why-a-script-and-the-rstudio-panes utf-8 LF