Skip to contents

Takes a large table, common rows, and header information and constructs a table that is a subset of those components using supplied ranges of rows and columns.

Usage

build_span(
  table_body = NULL,
  row_common = NULL,
  table_body_head = NULL,
  row_common_head = NULL,
  header_format = "text",
  obnd = NULL,
  row_sel = NULL,
  col_sel = NULL,
  table_alignment = "center",
  inner_border = officer::fp_border(color = "black", width = 0.3),
  outer_border = officer::fp_border(color = "black", width = 2),
  set_header_inner_border_v = TRUE,
  set_header_inner_border_h = TRUE,
  set_header_outer_border = TRUE,
  set_body_inner_border_v = TRUE,
  set_body_inner_border_h = FALSE,
  set_body_outer_border = TRUE,
  notes_detect = NULL
)

Arguments

table_body

Data frame with the body of the large table.

row_common

Data frame with the common rows.

table_body_head

Data frame or matrix with headers for the table body.

row_common_head

Data frame or matrix with headers for the common rows.

header_format

Format of the header either "text" (default) or "md" for markdown.

obnd

Optional onbrand object used to format markdown. The default NULL value will use default formatting.

row_sel

Indices of rows to build to the table with.

col_sel

Indices of columns to build to the table with.

table_alignment

Character string specifying the alignment #'of the table (body and headers). Can be "center" (default), "left", "right", or "justify"

inner_border

Border object for inner border lines defined using officer::fp_border()

outer_border

Border object for outer border lines defined using officer::fp_border()

set_header_inner_border_v

Boolean value to enable or disable inner vertical borders for headers

set_header_inner_border_h

Boolean value to enable or disable inner horizontal borders for headers

set_header_outer_border

Boolean value to enable or disable outer border for headers

set_body_inner_border_v

Boolean value to enable or disable inner vertical borders for the body

set_body_inner_border_h

Boolean value to enable or disable inner horizontal borders for the body

set_body_outer_border

Boolean value to enable or disable outer border borders for the body

notes_detect

Vector of strings to detect in output tables (example c("NC", "BLQ")).

Value

list with the following elements

  • df: Data frame with the built table.

  • ft: The data frame as a flextable object.

  • notes: Note placeholders found in the table.

Details

The way the data frames relate to each other are mapped out below. The dimensions of the different data frames are identified below (nrow x ncol)


                            col_sel
                      |<--------------->|

|--------------------------------------------| ---
|                 |   .                 .    |  ^
|                 |   .                 .    |  |
| row_common_head |   . table_body_head .    |  | m
|      m x n      |   .      m x c      .    |  |
|                 |   .                 .    |  v
|--------------------------------------------| ---
|                 |   .                 .    |  ^
|                 |   .                 .    |  |
|    row_common   |   .   table_body    .    |  |
|      r x n      |   .     r x c       .    |  |
|                 |   .                 .    |  |
|.................|..........................|  |     -
|                 |   ./  /  /  /  /  / .    |  |     ^
|                 |   .  /  /  /  /  /  .    |  | r   |
|                 |   . /  /  /  /  /  /.    |  |     | row_sel
|                 |   ./  /  /  /  /  / .    |  |     |
|                 |   .  /  /  /  /  /  .    |  |     v
|.................|...../../../../../../.... |  |     -
|                 |   .                 .    |  |
|                 |   .                 .    |  v
|--------------------------------------------| ---

|<--------------->|<------------------------>|
        n                    c

Examples

if(interactive()){

tbl_res = mk_lg_tbl()

res =
span_table(table_body      = tbl_res$lg_tbl_body,
           row_common      = tbl_res$lg_tbl_row_common,
           table_body_head = tbl_res$lg_tbl_body_head,
           row_common_head = tbl_res$lg_tbl_row_common_head,
           max_row         = 20,
           max_col         = 10,
           notes_detect    = c("BQL", "NC"))


# Notes detected in the first table:
res[["tables"]][["Table 1"]][["notes"]]

# First table as a data frame:
res[["tables"]][["Table 1"]][["df"]]

# First table as a flextable:
res[["tables"]][["Table 1"]][["ft"]]

}