Closed ddsjoberg closed 1 month ago
Something like this could work? Not sure about it though
theme_gtsummary_pharma <- function(set_theme = TRUE, font_size = NULL) {
# start with the compact theme -----------------------------------------------
lst_theme <- theme_gtsummary_compact(set_theme = FALSE, font_size = font_size)
lst_theme$`pkgwide-str:theme_name` <- "Pharmaceutical"
# updating with some pharma-specific bits ------------------------------------
lst_theme <- lst_theme |>
append(
list(
"tbl_summary-str:default_con_type" = "continuous2",
"tbl_summary-arg:statistic" =
list(all_continuous() ~ c("{median} ({p25}, {p75})", "{mean} ({sd})", "{min}, {max}"),
all_categorical() ~ "{n} ({p}%)"),
"tbl_summary-fn:percent_fun" = label_style_percent(digits = 1),
"pkgwide-fn:pvalue_fun" = label_style_pvalue(digits = 2),
"tbl_summary-fn:addnl-fn-to-run" = function(x) add_stat_label(x) |> bold_labels()
)
)
# add a monospace font for gt ------------------------------------------------
lst_theme$`as_gt-lst:addl_cmds` <-
c(lst_theme$`as_gt-lst:addl_cmds`,
list(tab_spanner = expr(gt::opt_table_font(stack = "monospace-code"))))
# finishing up ---------------------------------------------------------------
if (set_theme == TRUE) set_gtsummary_theme(lst_theme)
return(invisible(lst_theme))
}
theme_gtsummary_pharma()
tbl_summary(trial, by = trt, include = c(age, grade, response)) |> add_p()
Added a proto-type here: https://insightsengineering.github.io/crane/reference/theme_gtsummary_roche.html
Will develop it there, and perhaps migrate here one day?
I think we could do something as simple as the compact theme +
gt::opt_table_font(stack = "monospace-code")
(and one for flextable, maybe)?