Parameterized reporting keeps the same template while changing the values inserted into it.

Program

Play the script to choose a region and see the caption update from the same template.

region_index
parameterized_caption.R
Replay: real traced execution (multi-file project)
regions <- c("north", "south", "west")
region_index <- 1
count <- c(12, 9, 15)[region_index]
region <- regions[region_index]
caption <- paste("Region", region, "has", count, "records")
cat(caption, "\n", sep = "")
regions <- c("north", "south", "west")
region_index <- 2
count <- c(12, 9, 15)[region_index]
region <- regions[region_index]
caption <- paste("Region", region, "has", count, "records")
cat(caption, "\n", sep = "")
regions <- c("north", "south", "west")
region_index <- 3
count <- c(12, 9, 15)[region_index]
region <- regions[region_index]
caption <- paste("Region", region, "has", count, "records")
cat(caption, "\n", sep = "")
  1. regions ← north, south, west

    1regions <- c("north", "south", "west")2region_index <- 1
    values this stepnorth, south, westregions
  2. region_index ← 1

    1regions <- c("north", "south", "west")2region_index <- 13count <- c(12, 9, 15)[region_index]
    values this step1region_index
  3. count ← 12

    2region_index <- 13count <- c(12, 9, 15)[region_index]4region <- regions[region_index]
    values this step12count1region_index
  4. region ← north

    3count <- c(12, 9, 15)[region_index]4region <- regions[region_index]5caption <- paste("Region", region, "has", count, "records")
    values this stepnorthregionnorth, south, westregions1region_index
  5. caption ← Region north has 12 records

    4region <- regions[region_index]5caption <- paste("Region", region, "has", count, "records")6cat(caption, "\n", sep = "")
    values this stepRegion north has 12 recordscaptionnorthregion12count
  6. cat(caption, " ", sep = "")

    5caption <- paste("Region", region, "has", count, "records")6cat(caption, "\n", sep = "")
    outputRegion north has 12 records
    values this stepRegion north has 12 recordscaption
  1. regions ← north, south, west

    1regions <- c("north", "south", "west")2region_index <- 2
    values this stepnorth, south, westregions
  2. region_index ← 2

    1regions <- c("north", "south", "west")2region_index <- 23count <- c(12, 9, 15)[region_index]
    values this step2region_index
  3. count ← 9

    2region_index <- 23count <- c(12, 9, 15)[region_index]4region <- regions[region_index]
    values this step9count2region_index
  4. region ← south

    3count <- c(12, 9, 15)[region_index]4region <- regions[region_index]5caption <- paste("Region", region, "has", count, "records")
    values this stepsouthregionnorth, south, westregions2region_index
  5. caption ← Region south has 9 records

    4region <- regions[region_index]5caption <- paste("Region", region, "has", count, "records")6cat(caption, "\n", sep = "")
    values this stepRegion south has 9 recordscaptionsouthregion9count
  6. cat(caption, " ", sep = "")

    5caption <- paste("Region", region, "has", count, "records")6cat(caption, "\n", sep = "")
    outputRegion south has 9 records
    values this stepRegion south has 9 recordscaption
  1. regions ← north, south, west

    1regions <- c("north", "south", "west")2region_index <- 3
    values this stepnorth, south, westregions
  2. region_index ← 3

    1regions <- c("north", "south", "west")2region_index <- 33count <- c(12, 9, 15)[region_index]
    values this step3region_index
  3. count ← 15

    2region_index <- 33count <- c(12, 9, 15)[region_index]4region <- regions[region_index]
    values this step15count3region_index
  4. region ← west

    3count <- c(12, 9, 15)[region_index]4region <- regions[region_index]5caption <- paste("Region", region, "has", count, "records")
    values this stepwestregionnorth, south, westregions3region_index
  5. caption ← Region west has 15 records

    4region <- regions[region_index]5caption <- paste("Region", region, "has", count, "records")6cat(caption, "\n", sep = "")
    values this stepRegion west has 15 recordscaptionwestregion15count
  6. cat(caption, " ", sep = "")

    5caption <- paste("Region", region, "has", count, "records")6cat(caption, "\n", sep = "")
    outputRegion west has 15 records
    values this stepRegion west has 15 recordscaption
parameter `region_index` is a small parameter that controls the report value.
lookup `regions[region_index]` maps the parameter to display text.
template `paste` fills the same caption shape with selected values.