How do I include return characters in tbl_regression from gtsummary?

Viewed 34

I am trying to figure out how to introduce return characters in tbl_regression from gtsummary. I have tried the following code on R 4.2.1 on Ubuntu 22.04 with no luck.

  library(gtsummary)
  library(gt)
  m1 <- glm(response ~ age + stage, trial, family = binomial)
  
  tbl_regression(m1, exponentiate = TRUE,
                 label = list(
                   stage ~ "No\nCR"
                 ))
  
  tbl_regression(m1, exponentiate = TRUE,
                 label = list(
                   stage ~ "Still<br>No<br>CR"
                 ))
  
  tbl_regression(m1, exponentiate = TRUE,
                 label = list(
                   stage ~ html("Still<br>No<br>CR")
                 ))

1 Answers

We can use gt::fmt_markdown() and before doing that we need to convert gtsummary table to a gt table and then apply fmt_markdown .

library(gtsummary)
library(gt)

m1 <- glm(response ~ age + stage, trial, family = binomial)

tbl_regression(m1, exponentiate = TRUE,
               label = list(
                 stage ~ "No <br> CR"
               )) %>% 
  as_gt() %>% 
  fmt_markdown(columns = everything())
Related