Spanning headers are a common requirement of regulatory tables, yet few reporting packages support them. The reporter package supports any number of spanning levels, along with a simple and flexible syntax to define them.
library(reporter)
# Create temporary path
<- file.path(tempdir(), "example5.pdf")
tmp
# Prepare Data
<- mtcars[1:10, ]
dat <- data.frame(vehicle = rownames(dat), dat)
df
# Define Table with spanning headers
<- create_table(df) %>%
tbl titles("Table 1.0", "MTCARS Spanning Headers") %>%
spanning_header(from = "mpg", to = "hp", label = "Span 1", n = 10) %>%
spanning_header(from = "drat", to = "qsec", label = "Span 2", n = 10) %>%
spanning_header(from = "vs", to = "carb", label = "Span 3", n = 10) %>%
spanning_header(from = "drat", to = "carb",
label = "Super Span", level = 2) %>%
define(vehicle, label = "Vehicle") %>%
define(mpg, format = "%.1f") %>%
define(disp, visible = FALSE) %>%
define(am, visible = FALSE) %>%
footnotes("* Motor Trend, 1974")
# Create Report and add table
<- create_report(tmp, output_type = "PDF",
rpt font = "Courier", font_size = 12) %>%
page_header(left = "Client: Motor Trend", right = "Study: Cars") %>%
add_content(tbl) %>%
page_footer(left = Sys.time(),
center = "Confidential",
right = "Page [pg] of [tpg]")
# Write the report
<- write_report(rpt)
res
# file.show(tmp)
Next: Example 6: Page Wrap