How can I convert a gt_tbl object into a flextable object?

582 views Asked by At

I've been struggling to export my gt_tbl object to Word, because the output ignores all formatting as mentioned in previous posts (**gt** will not format column labels in Word output)

I thought a reasonable solution would be to convert my gt_tbl object to a flextable and then export as a Word. However, I could not find any function capable of this.

There's a function called as_flex_table from the gtsummary package, but when I try to use it I get the following message:

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

I also thought of scrapping the gt table altogether and creating a flextable from scratch, but gt has some features that are too difficult to implement with other packages, such as the tab_row_group function. Here's an example below:

table1 <- gtcars %>%  dplyr::select(model, year, hp, trq) %>%
  dplyr::slice(1:8) %>% gt(rowname_col = "model") %>%
  tab_row_group(label = "powerful", rows = hp <= 600) %>%
  tab_row_group(label = "super powerful", rows = hp > 600)

table1 %>% as_flex_table() #This returns the error

I really can't find any function to convert a gt_tbl to either a flextable or gtsummary object, please I need some help :(

0

There are 0 answers