cols_unhide: Unhide one or more columns

View source: R/cols_hide.R

cols_unhideR Documentation

Unhide one or more columns

Description

cols_unhide() allows us to take one or more hidden columns (usually done via cols_hide()) and make them visible in the final output table. This may be important in cases where the user obtains a gt_tbl object with hidden columns and there is motivation to reveal one or more of those.

Usage

cols_unhide(data, columns)

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.

columns

Columns to target

⁠<column-targeting expression>⁠ // default: everything()

The columns to unhide in the output display table. Can either be a series of column names provided in c(), a vector of column indices, or a select helper function (e.g. starts_with(), ends_with(), contains(), matches(), num_range(), and everything()).

Details

The hiding and unhiding of columns is internally a rendering directive, so, all columns that are 'hidden' are still accessible and useful in any expression provided to a rows argument. The cols_unhide() function quietly changes the visible state of a column (much like the cols_hide() function) and doesn't yield warnings or messages when changing the state of already-visible columns.

Value

An object of class gt_tbl.

Examples

Let's use a small portion of the countrypops dataset to create a gt table. We'll hide the country_code_2 and country_code_3 columns with cols_hide().

tab_1 <-
  countrypops |>
  dplyr::filter(
    country_name == "Singapore",
    year %in% 2017:2021
  ) |>
  gt() |>
  cols_hide(columns = c(country_code_2, country_code_3))

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

If the tab_1 object is provided without the code or source data to regenerate it, and, the user wants to reveal otherwise hidden columns then cols_unhide() becomes useful.

tab_1 |> cols_unhide(columns = country_code_2)
This image of a table was generated from the second code example in the `cols_unhide()` help file.

Function ID

5-13

Function Introduced

v0.3.0 (May 12, 2021)

See Also

cols_hide() to perform the inverse operation.

Other column modification functions: cols_add(), cols_align(), cols_align_decimal(), cols_hide(), cols_label(), cols_label_with(), cols_merge(), cols_merge_n_pct(), cols_merge_range(), cols_merge_uncert(), cols_move(), cols_move_to_end(), cols_move_to_start(), cols_nanoplot(), cols_units(), cols_width()


rstudio/gt documentation built on Nov. 2, 2024, 5:53 p.m.