R: Markdown or HTML markup in `gtsummary` tables

To 100% honest, I don’t know why this solution works…but it does! The {gt} package has a function called fmt_markdown() that is meant to convert markdown syntax to the specified output type. BUT in your example, the markdown superscript is not recognized (more on why here https://github.com/rstudio/gt/issues/129#issuecomment-663753251). BUUUUT, when I apply that function to your HTML tag superscripts, they are recognized and you get the output you’re looking for.

library(gtsummary)
library(nycflights13)

lm_1 <- lm(arr_delay ~ air_time + sched_dep_time , flights)

tbl_regression(lm_1, 
               label = list(air_time ~ "Air<sup>time</sup>",
                            sched_dep_time ~ "Departure<sup>time</sup>")) %>% 
  add_glance_source_note(include = 'r.squared') %>%
  as_gt() %>%
  gt::fmt_markdown(columns = vars(label))

enter image description here

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top