Skip to content

feat: add the omit_na_group arg to gt() - #2062

Merged
rich-iannone merged 3 commits into
masterfrom
feat-groupname-col-omit-na
Oct 21, 2025
Merged

rich-iannone merged 3 commits into
masterfrom
feat-groupname-col-omit-na

Conversation

@rich-iannone

Copy link
Copy Markdown
Member

This PR adds the omit_na_group arg to the gt() function. If TRUE, rows with NA values in the groupname_col be excluded from row group assignment. The default (FALSE) preserves the old behavior where rows with NA in groupname_col are assigned to a group called "NA".

When set to TRUE, rows with NA values will appear as ungrouped rows in the table body. This will be useful for including header or separator rows that shouldn't belong to any particular row group.

library(tidyverse)
library(gt)

gtcars |> 
  dplyr::filter(ctry_origin == "Germany") |> 
  dplyr::select(1:5) |> 
  dplyr::add_row(
    mfr = NA_character_,
    model = "Some great German cars:",
    .before = 1 
  ) |> 
  gt(
    rowname_col = "model",
    groupname_col = "mfr",
    omit_na_group = TRUE
  )
image

Fixes: #1215

@rich-iannone
rich-iannone marked this pull request as ready for review October 21, 2025 03:56
@rich-iannone
rich-iannone merged commit 2efd216 into master Oct 21, 2025
1 check passed
@rich-iannone
rich-iannone deleted the feat-groupname-col-omit-na branch October 21, 2025 04:11
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.

Option to omit groupname_cols with NA values

1 participant