I'm using tbl_stack to combine two tables and I have a group header for each table.
It looks fine when I view the table in R - however, when I export the document to .docx format, flextable is adding a column for the group header. Is there a way to make it keep the group header as just a row separating the two tables - not a whole new column?
library(gtsummary)
table1a<-trial %>%
tbl_summary(
by = trt,
include = c(marker, age, stage)
)
table1b<-trial %>%
tbl_summary(
by = trt,
include = c(response, death)
)
table1<-tbl_stack(list(table1a, table1b),
group_header = c("First section","Second section"))
table1f<-as_flex_table(table1)
flextable::save_as_docx(table1f, path = "~/Desktop/table.docx")
The left is how it looks in R, the right is how it shows up in Word
I'm using tbl_stack to combine two tables and I have a group header for each table.
It looks fine when I view the table in R - however, when I export the document to .docx format, flextable is adding a column for the group header. Is there a way to make it keep the group header as just a row separating the two tables - not a whole new column?
library(gtsummary)
table1a<-trial %>%
tbl_summary(
by = trt,
include = c(marker, age, stage)
)
table1b<-trial %>%
tbl_summary(
by = trt,
include = c(response, death)
)
table1<-tbl_stack(list(table1a, table1b),
group_header = c("First section","Second section"))
table1f<-as_flex_table(table1)
flextable::save_as_docx(table1f, path = "~/Desktop/table.docx")
The left is how it looks in R, the right is how it shows up in Word
Share Improve this question asked Mar 26 at 17:41 John RyanJohn Ryan 3831 silver badge11 bronze badges1 Answer
Reset to default 1When a gtsummary table is printed with gt (the default), the row header feature is used that is supported within gt. But when we convert a gtsummary to flextable, we can't use the same row header feature from gt, and the new column is added.
FYI In an upcoming release of gtsummary, more stacking options will be available https://github/ddsjoberg/gtsummary/issues/2141