rm_caption: Remove the table caption

View source: R/tab_remove.R

rm_captionR Documentation

Remove the table caption

Description

We can easily remove the caption text from a gt table with rm_caption(). The caption may exist if it were set through the gt() caption argument or via tab_caption().

This function for removal is useful if you have received a gt table (perhaps through an API that returns gt objects) but would prefer that the table not have a caption at all. This function is safe to use even if there is no table caption set in the input gt_tbl object.

Usage

rm_caption(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

Use a portion of the gtcars dataset to create a gt table. We'll add a header part with the tab_header() function, and, a caption will also be added via the tab_caption() function.

gt_tbl <-
  gtcars |>
  dplyr::select(mfr, model, msrp) |>
  dplyr::slice(1:5) |>
  gt() |>
  tab_header(
    title = md("Data listing from **gtcars**"),
    subtitle = md("`gtcars` is an R dataset")
  ) |>
  tab_caption(caption = md("**gt** table example."))

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

If you decide that you don't want the caption in the gt_tbl object, it can be removed with the rm_caption() function.

rm_caption(data = gt_tbl)
This image of a table was generated from the second code example in the `rm_caption()` help file.

Function ID

7-6

Function Introduced

v0.8.0 (November 16, 2022)

See Also

Other part removal functions: rm_footnotes(), rm_header(), rm_source_notes(), rm_spanners(), rm_stubhead()


rstudio/gt documentation built on April 29, 2024, 10:37 p.m.