Skip to contents

Turns a spi_field_guide() result into a formatted table, in either of two layouts, using gt or flextable. Optionally saves to file; the format is inferred from the extension (html / docx / pdf / rtf / png / pptx).

Usage

spi_field_guide_table(
  x,
  engine = c("gt", "flextable"),
  layout = c("scan", "worked"),
  year = NULL,
  districts = NULL,
  name_col = NULL,
  file = NULL,
  shade = TRUE,
  max_rows = 50L,
  ...
)

Arguments

x

A spi_field_guide() result (class spi_field_guide).

engine

Table engine: "gt" or "flextable".

layout

"scan" (districts as rows) or "worked" (components as rows).

year

Focal year. Default: NULL (x$read_year).

districts

Character vector of district ids for the "worked" layout. Default: NULL (select four districts with different findings).

name_col

Column to label districts by. Default: NULL (first of adm2_name, adm1_name, else the id column).

file

Optional output path; the extension sets the format. Default: NULL (return the table object without saving).

shade

Logical. Apply concern shading. Default: TRUE.

max_rows

Integer. For the "scan" layout, cap the number of rows (priority for review first, then by size of shortfall). Default: 50.

...

Passed to the underlying gt::gtsave() / flextable saver.

Value

The gt_tbl or flextable object, invisibly when file is set.

Details

Two layouts:

  • "scan" – one row per district for the focal year, with the STEPS components and the label; the label cell is shaded.

  • "worked" – the field guide's teaching layout: the five STEPS components, the conventional NPAFP rate and the label as rows, a few districts as columns, every cell shaded as adding to concern (rose), intermediate (amber) or reassuring (green). When districts is NULL, four districts (SPI at or above 1, an uncertain shortfall, a large shortfall with supporting evidence, and a shortfall without wider area concern) are selected.

Examples

fg <- synth_field_guide
if (FALSE) { # \dontrun{
spi_field_guide_table(fg, engine = "gt", layout = "worked")
spi_field_guide_table(fg, engine = "gt", layout = "scan",
                     file = tempfile(fileext = ".html"))
spi_field_guide_table(fg, engine = "flextable", layout = "worked",
                     file = tempfile(fileext = ".docx"))
} # }