cols_hide: Hide one or more columns

Description Usage Arguments Details Value Figures Function ID See Also Examples

View source: R/modify_columns.R

Description

The cols_hide() function allows us to hide one or more columns from appearing in the final output table. While it's possible and often desirable to omit columns from the input table data before introduction to the gt() function, there can be cases where the data in certain columns is useful (as a column reference during formatting of other columns) but the final display of those columns is not necessary.

Usage

1
cols_hide(data, columns)

Arguments

data

A table object that is created using the gt() function.

columns

The column names to hide from the output display table. The order of the remaining columns will be preserved. Values provided that do not correspond to column names will be disregarded.

Details

The hiding 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. Furthermore, the cols_hide() function (as with many gt functions) can be placed anywhere in a pipeline of gt function calls (acting as a promise to hide columns when the timing is right). However there's perhaps greater readability when placing this call closer to the end of such a pipeline.

Value

An object of class gt_tbl.

Figures

Function ID

4-7

See Also

Other Modify Columns: cols_align(), cols_label(), cols_merge_range(), cols_merge_uncert(), cols_merge(), cols_move_to_end(), cols_move_to_start(), cols_move(), cols_width()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Use `countrypops` to create a gt table;
# Hide the columns `country_code_2` and
# `country_code_3`
tab_1 <-
  countrypops %>%
  dplyr::filter(country_name == "Mongolia") %>%
  tail(5) %>%
  gt() %>%
  cols_hide(
    columns = vars(
      country_code_2, country_code_3)
  )

# Use `countrypops` to create a gt table;
# Use the `population` column to provide
# the conditional placement of footnotes,
# then hide that column and one other
tab_2 <-
  countrypops %>%
  dplyr::filter(country_name == "Mongolia") %>%
  tail(5) %>%
  gt() %>%
  cols_hide(
    columns = vars(country_code_3, population)
  ) %>%
  tab_footnote(
    footnote = "Population above 3,000,000.",
    locations = cells_body(
      columns = vars(year),
      rows = population > 3000000)
  )

gt documentation built on Aug. 6, 2020, 1:07 a.m.