R Date values support calendar arithmetic. Adding a number to a Date moves by that many days.

Program

Play the script to compute a due date and format it for display.

dates.R
Replay: real traced execution (multi-file project)
start <- as.Date("2026-05-01")
due <- start + 14
label <- format(due, "%b %d")
cat(label, "\n", sep = "")
  1. start ← 2026-05-01

    1start <- as.Date("2026-05-01")2due <- start + 14
    values this step2026-05-01start
  2. due ← 2026-05-15

    1start <- as.Date("2026-05-01")2due <- start + 143label <- format(due, "%b %d")
    values this step2026-05-15due2026-05-01start
  3. label ← May 15

    2due <- start + 143label <- format(due, "%b %d")4cat(label, "\n", sep = "")
    values this stepMay 15label2026-05-15due
  4. cat(label, " ", sep = "")

    3label <- format(due, "%b %d")4cat(label, "\n", sep = "")
    outputMay 15
    values this stepMay 15label

Follow the Date

  1. start is 2026-05-01.
  2. Adding 14 days makes due equal 2026-05-15.
  3. format(due, "%b %d") turns the date into May 15.
  4. The script prints May 15. | name | value | | --- | --- | | start | 2026-05-01 | | days added | 14 | | due | 2026-05-15 | | label | May 15 |
as.Date `as.Date` converts date text to a Date value.
date arithmetic `start + 14` advances the date by fourteen days.
format `format` turns a Date into display text.

Exercise: dates.R

Reproduce May 15, then trace how adding 14 days changes the start date.