tab_info: Understand what's been set inside of a *gt* table object

View source: R/tab_info.R

tab_infoR Documentation

Understand what's been set inside of a gt table object

Description

It can become increasingly difficult to recall the ID values associated with different labels in a gt table. Further to this, there are also situations where gt will generate ID values on your behalf (e.g., with tab_spanner_delim(), etc.) while ensuring that duplicate ID values aren't produced. For the latter case, it is impossible to know what those ID values are unless one were to carefully examine to correct component of the gt_tbl object.

Because it's so essential to know these ID values for targeting purposes (when styling with tab_style(), adding footnote marks with tab_footnote(), etc.), tab_info() can help with all of this. It summarizes (by location) all of the table's ID values and their associated labels. The product is an informational gt table, designed for easy retrieval of the necessary values.

Usage

tab_info(data)

Arguments

data

The gt table data object

⁠obj:<gt_tbl>⁠ // required

This is the gt table object that is commonly created through use of the gt() function.

Value

An object of class gt_tbl.

Examples

Let's use a portion of the gtcars dataset to create a gt table. We'll use tab_spanner() to group two columns together under a spanner column with the ID and label "performance". Finally, we can usetab_info() in a separate, interactive statement so that we can inspect a table that summarizes the ID values any associated label text for all parts of the table.

gt_tbl <-
  gtcars |>
  dplyr::select(model, year, starts_with("hp"), msrp) |>
  dplyr::slice(1:4) |>
  gt(rowname_col = "model") |>
  tab_spanner(
    label = "performance",
    columns = starts_with("hp")
  )

gt_tbl |> tab_info()
This image of a table was generated from the first code example in the `tab_info()` help file.

Function ID

2-12

Function Introduced

v0.8.0 (November 16, 2022)

See Also

Other part creation/modification functions: tab_caption(), tab_footnote(), tab_header(), tab_options(), tab_row_group(), tab_source_note(), tab_spanner(), tab_spanner_delim(), tab_stub_indent(), tab_stubhead(), tab_style(), tab_style_body()


rstudio/gt documentation built on Dec. 2, 2024, 11:05 a.m.