Skip to content

tab_stubhead() errors in RTF when there are fewer labels than columns #2118

@bzkrouse

Description

@bzkrouse

Prework

Description

Thanks for all the efforts to support flexible output types! We noticed the following issue for RTF specifically:

For tables with multi-column stub (multiple rowname_col's and/or row_grp_as_column = TRUE), we can use tab_stubhead() to define the labels. These can be one label for all columns, one label per column, or no labels. All works well in HTML but doing 1 label or no labels fails in RTF:

library(gt)

# Both stubs labeled - OK
tab1 <- exibble |>
  gt(
    rowname_col = c("group", "char")
  )|> 
  tab_stubhead(
    label = c("Group","Char")
  ) 

tab1 |> 
  gt::gtsave("test.rtf")

# Both stubheads labeled w/ empty strings - OK
tab2 <- exibble |>
  gt(
    rowname_col = c("group", "char")
  )|>   
  tab_stubhead(
    label = c("","")
  ) 

tab2 |> 
  gt::gtsave("test.rtf")

# One stubhead label - Error
tab3 <- exibble |>
  gt(
    rowname_col = c("group", "char")
  ) |>   
  tab_stubhead(
    label = c("Group / Char")
  ) 

tab3 |> 
  gt::gtsave("test.rtf")
#> Error in `x[[i]]`:
#> ! subscript out of bounds

# No stubhead labels - Error
tab4 <- exibble |>
  gt(
    rowname_col = c("group", "char")
  )

tab4 |> 
  gt::gtsave("test.rtf")
#> Error in `x[[i]]`:
#> ! subscript out of bounds

Created on 2026-01-26 with reprex v2.1.1

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions