Reporting Workflows
Parameterized Caption
Reused Text
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.
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 = "")
regions ← north, south, west
1regions <- c("north", "south", "west")2region_index <- 1values this stepnorth, south, westregionsregion_index ← 1
1regions <- c("north", "south", "west")2region_index <- 13count <- c(12, 9, 15)[region_index]values this step1region_indexcount ← 12
2region_index <- 13count <- c(12, 9, 15)[region_index]4region <- regions[region_index]values this step12count1region_indexregion ← north
3count <- c(12, 9, 15)[region_index]4region <- regions[region_index]5caption <- paste("Region", region, "has", count, "records")values this stepnorthregionnorth, south, westregions1region_indexcaption ← 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 recordscaptionnorthregion12countcat(caption, " ", sep = "")
5caption <- paste("Region", region, "has", count, "records")6cat(caption, "\n", sep = "")outputRegion north has 12 recordsvalues this stepRegion north has 12 recordscaption
regions ← north, south, west
1regions <- c("north", "south", "west")2region_index <- 2values this stepnorth, south, westregionsregion_index ← 2
1regions <- c("north", "south", "west")2region_index <- 23count <- c(12, 9, 15)[region_index]values this step2region_indexcount ← 9
2region_index <- 23count <- c(12, 9, 15)[region_index]4region <- regions[region_index]values this step9count2region_indexregion ← south
3count <- c(12, 9, 15)[region_index]4region <- regions[region_index]5caption <- paste("Region", region, "has", count, "records")values this stepsouthregionnorth, south, westregions2region_indexcaption ← 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 recordscaptionsouthregion9countcat(caption, " ", sep = "")
5caption <- paste("Region", region, "has", count, "records")6cat(caption, "\n", sep = "")outputRegion south has 9 recordsvalues this stepRegion south has 9 recordscaption
regions ← north, south, west
1regions <- c("north", "south", "west")2region_index <- 3values this stepnorth, south, westregionsregion_index ← 3
1regions <- c("north", "south", "west")2region_index <- 33count <- c(12, 9, 15)[region_index]values this step3region_indexcount ← 15
2region_index <- 33count <- c(12, 9, 15)[region_index]4region <- regions[region_index]values this step15count3region_indexregion ← west
3count <- c(12, 9, 15)[region_index]4region <- regions[region_index]5caption <- paste("Region", region, "has", count, "records")values this stepwestregionnorth, south, westregions3region_indexcaption ← 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 recordscaptionwestregion15countcat(caption, " ", sep = "")
5caption <- paste("Region", region, "has", count, "records")6cat(caption, "\n", sep = "")outputRegion west has 15 recordsvalues 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.