最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

flextable adding a new column when using tbl_stack in gtsummary - Stack Overflow

programmeradmin9浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 1

When 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

发布评论

评论列表(0)

  1. 暂无评论