Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using gt functions to style gtsummary merged tables

I’ve been utilising the as_gt() function to format my gtsummary tables and this works fine on each individual table. But when trying to merge tables (tbl_merge) together this error appears:

Error: Error in argument 'x='. Expecting object of class 'gtsummary'

This happens regardless of feeding the gt format options to each individual table, or only to the merged object, same error. Any ideas on workarounds? Repex below.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

library(survival)
library(tidyverse)
library(gt)
library(gtsummary)

# Works fine for individual tbls
t1 <-
  glm(response ~ trt + grade + age, trial, family = binomial) %>%
  tbl_regression(exponentiate = TRUE) %>%
  as_gt() %>%
      gt::tab_options(table.font.names = "Times New Roman")
t1

t2 <-
  coxph(Surv(ttdeath, death) ~ trt + grade + age, trial) %>%
  tbl_regression(exponentiate = TRUE)

# Error appears
tbl_merge_ex1 <-
  tbl_merge(
    tbls = list(t1, t2),
    tab_spanner = c("**Tumor Response**", "**Time to Death**") %>%
      as_gt() %>%
      gt::tab_options(table.font.names = "Times New Roman")
  )

Error: Error in argument 'x='. Expecting object of class 'gtsummary'

>Solution :

you need to remove all as_gt() until the very end after the merge like so:

library(survival)
library(tidyverse)
library(gt)
library(gtsummary)



t1 <-
  glm(response ~ trt + grade + age, trial, family = binomial) %>%
  tbl_regression(exponentiate = TRUE) 

t2 <-
  coxph(Surv(ttdeath, death) ~ trt + grade + age, trial) %>%
  tbl_regression(exponentiate = TRUE)


tbl_merge_ex1 <-
  tbl_merge(
    tbls = list(t1, t2),
    tab_spanner = c("**Tumor Response**", "**Time to Death**") 
  ) %>%
  as_gt() %>%
  gt::tab_options(table.font.names = "Times New Roman")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading