Skip to contents

Formats a data frame as a Markdown pipe table for Quarto or R Markdown documents and GitHub pages, using knitr::kable(). Numbers are rounded to three decimals unless digits is given. The knitr package is required.

Usage

cacs_summary_as_markdown(summary_tbl, ...)

Arguments

summary_tbl

A data frame, such as one of the elements rates_breakdown, rates_per_site, and rates_per_site_moe of a summary made by summary.cacs_run_result().

...

Arguments passed to knitr::kable(), such as digits, caption, col.names, or align. The format is always "pipe", so format gives an error.

Value

A character vector of class knitr_kable with the lines of the table, and of the caption if there is one. Printing it shows the table.

Details

A table with a site_id column and a column for at least one of the five rates, such as rates_per_site or rates_per_site_moe, is changed in two ways. Its columns are put in the order site_id, drive_time_min (if present), the rates in the order of cacs_acs_default_rates, and any other columns. A caption is added unless caption is given. When the cells are text, as in rates_per_site_moe, the caption says that they show estimates with margins of error (half-widths of confidence intervals), at the confidence level in the table's attribute cacs_confidence_level, which summary.cacs_run_result() sets. For a table without that attribute, the caption gives no level.

Examples

if (requireNamespace("knitr", quietly = TRUE)) {
  # A made-up table shaped like the rates_breakdown element of a summary
  summary_tbl <- tibble::tibble(
    variable = "poverty_rate",
    mean = 0.1234,
    sd = 0.0567,
    n_NA = 0L
  )
  cacs_summary_as_markdown(summary_tbl)
}
#> 
#> 
#> |variable     |  mean|    sd| n_NA|
#> |:------------|-----:|-----:|----:|
#> |poverty_rate | 0.123| 0.057|    0|