The cols_hide() function

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

countrypops |>
  dplyr::filter(
    country_name == "Egypt",
    year %in% 2017:2021
  ) |>
  gt() |>
  cols_hide(columns = c(country_code_2, country_code_3))
country_name year population
Egypt 2017 101789386
Egypt 2018 103740765
Egypt 2019 105618671
Egypt 2020 107465134
Egypt 2021 109262178

Using another countrypops-based gt table, we can use the population column to provide the conditional placement of footnotes. Then, we’ll hide that column along with the country_code_3 column. Note that the order of cols_hide() and tab_footnote() has no effect on the final display of the table.

countrypops |>
  dplyr::filter(
    country_name == "Pakistan",
    year %in% 2017:2021
  ) |>
  gt() |>
  cols_hide(columns = c(country_code_3, population)) |>
  tab_footnote(
    footnote = "Population above 220,000,000.",
    locations = cells_body(
      columns = year,
      rows = population > 220E6
    )
  )
country_name country_code_2 year
Pakistan PK 2017
Pakistan PK 2018
Pakistan PK 1 2019
Pakistan PK 1 2020
Pakistan PK 1 2021
1 Population above 220,000,000.