Skip to contents

Builds the gt table that write_html() and write_pdf() save, styled with a facade, so you can show it in a Quarto or R Markdown document, a Shiny app, or style it further with gt.

Usage

as_gt(
  data,
  title = NULL,
  subtitle = NULL,
  source_note = NULL,
  footnotes = NULL,
  names_separator = "__",
  facade = get_tsg_facade(which = "html")
)

Arguments

data

A tsg table or a data frame.

title

Optional title; defaults to the table's title (see add_table_title()).

subtitle

Optional subtitle; defaults to the table's subtitle.

source_note

Optional source note; defaults to the table's source note.

footnotes

Optional character vector of footnotes; defaults to the table's footnotes.

names_separator

Column name separator for spanners. Default "__".

facade

A built-in facade name (e.g. "booktabs"; see get_tsg_facade()), the path to a .yaml or .json facade file, or a facade list. Keys missing from it fall back to the html default facade; settings added with add_facade() take precedence over it.

Value

A gt_tbl object.

Examples

person_record |>
  generate_crosstab(marital_status, sex) |>
  add_table_title("Marital status by sex") |>
  as_gt(facade = "booktabs")
Marital status by sex
Marital status Total
Frequency
Percent
Male Female Male Female
Single/never married 1,544 859 685 55.63 44.37
Married 769 387 382 50.33 49.67
Common law/live-in 424 211 213 49.76 50.24
Widowed 138 40 98 28.99 71.01
Separated 43 19 24 44.19 55.81
Total 2,918 1,516 1,402 51.95 48.05