rgtsummary

Theme element "tbl_summary-arg:type" in gtsummary does not work


Theme element "tbl_summary-arg:type" in gtsummary does not work, though type argument works well with the same code

library(gtsummary)
packageVersion("gtsummary")
#> [1] '2.1.0.9010'

# Reset theme to defaults first
reset_gtsummary_theme()
tbl_summary(trial) |> 
  # Converting to a flextable object because gtsummary 
  # objects aren't rendered properly on Stack Overflow
  as_flex_table()


# Apply my theme
set_gtsummary_theme(list("tbl_summary-arg:type" =
                           list(all_dichotomous() ~ "categorical")))
# check if it works
trial |>
  tbl_summary() |> 
  as_flex_table()
#Not working Patient Died   is still presented as dichotomous

#Checking type argument
reset_gtsummary_theme()
trial |>
  tbl_summary(type = all_dichotomous() ~ "categorical") |> 
  as_flex_table()
#works well

Created on 2025-04-07 with reprex v2.1.1

Am I missing something making it not work?


Solution

  • This was just addressed in the dev version of the package. If you update your dev version, it should get you what you want.

    library(gtsummary)
    packageVersion("gtsummary")
    #> [1] '2.1.0.9013'
    
    list("tbl_summary-arg:type" = all_dichotomous() ~ "categorical") |> 
      set_gtsummary_theme()
    
    tbl_summary(trial, include = c(response, death), missing = "no") |> 
      bold_labels() |> 
      as_kable()
    
    Characteristic N = 200
    Tumor Response
    0 132 (68%)
    1 61 (32%)
    Patient Died
    0 88 (44%)
    1 112 (56%)

    Created on 2025-04-07 with reprex v2.1.1