Skip to content

feat: add the rows_hide() and rows_unhide() functions#2127

Merged
rich-iannone merged 15 commits intomasterfrom
feat-rows-hide
Feb 10, 2026
Merged

feat: add the rows_hide() and rows_unhide() functions#2127
rich-iannone merged 15 commits intomasterfrom
feat-rows-hide

Conversation

@rich-iannone
Copy link
Copy Markdown
Member

@rich-iannone rich-iannone commented Feb 10, 2026

This PR adds two new functions for controlling row visibility in gt tables, mirroring the existing cols_hide() and cols_unhide() functionality for columns. rows_hide() hides rows from the rendered output while keeping them accessible for row references and expressions. rows_unhide() reveals previously hidden rows.

In this new functionality, hidden rows are excluded from the rendered table but can still be targeted in rows expressions. Footnote and style indices automatically adjust to skip hidden rows. Summary rows (summary_rows(), grand_summary_rows()) calculate from visible rows only. Row groups with all rows hidden are automatically removed from the output.

Here's an example:

library(gt)

countrypops |>
  dplyr::filter(country_name == "Brazil", year %in% 2017:2021) |>
  gt(rowname_col = "year") |>
  fmt_integer(columns = population) |>
  rows_hide(rows = c("2018", "2020")) |>
  tab_footnote(
    footnote = "Peak year in this period.",
    locations = cells_body(columns = population, rows = year == 2021)
  )
image

This renders a table showing only 2017, 2019, and 2021.

Here's an example that tests for footnote rendering:

countrypops |>
  dplyr::filter(country_name == "Brazil", year %in% 2017:2021) |>
  gt(rowname_col = "year") |>
  fmt_integer(columns = population) |>
  tab_footnote(
    footnote = "2017",
    locations = cells_body(columns = population, rows = year == 2017)
  ) |>
  tab_footnote(
    footnote = "2018",
    locations = cells_body(columns = population, rows = year == 2018)
  ) |>
  tab_footnote(
    footnote = "2019",
    locations = cells_body(columns = population, rows = year == 2019)
  ) |>
  tab_footnote(
    footnote = "2020",
    locations = cells_body(columns = population, rows = year == 2020)
  ) |>
  tab_footnote(
    footnote = "2021",
    locations = cells_body(columns = population, rows = year == 2021)
  ) |>
  tab_footnote(
    footnote = "2017-2018",
    locations = cells_body(columns = population, rows = year %in% c(2017, 2018))
  ) |>
  tab_footnote(
    footnote = "2018-2019",
    locations = cells_body(columns = population, rows = year %in% c(2018, 2019))
  ) |>
  tab_footnote(
    footnote = "2019-2020",
    locations = cells_body(columns = population, rows = year %in% c(2019, 2020))
  ) |>
  tab_footnote(
    footnote = "2020-2021",
    locations = cells_body(columns = population, rows = year %in% c(2020, 202))
  ) |>
  rows_hide(rows = c("2018", "2020"))
image

This complex footnote example shows that the multiple inclusion of footnotes avoids hidden rows and the resultant numbering/marks is correct.

Fixes: #975

@rich-iannone rich-iannone merged commit cff38e6 into master Feb 10, 2026
19 of 21 checks passed
@rich-iannone rich-iannone deleted the feat-rows-hide branch February 10, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rows_hide() function to compliment cols_hide()

1 participant