gt icon indicating copy to clipboard operation
gt copied to clipboard

Issue exporting tbl_cross object with gtsave

Open anddis opened this issue 1 year ago • 0 comments

Description

Exporting an object of class tbl_cross as a .docx file using gtsummary::as_gt() followed by gt::gtsave() generates a Word file that, when opened, triggers this warning pop-up:

Word found unreadable content in t1.docx. Do you want to recover the contents of this document? If you trust the source of the document, click Yes

Clicking on Yes will open the document but the table's formatting is lost.

Reproducible example

library(gtsummary)
library(gt)
xxx <- mtcars |> 
  tbl_cross(row = vs, 
            col = am) |> 
  as_gt()
gtsave(xxx, "t1.docx")

Other useful info

I reported this issue here: https://github.com/ddsjoberg/gtsummary/issues/1613.

ddsjoberg proposed a temporary fix[*] and suggested to report this bug here too.

[*]:

It looks like the error is related to a column with a blank header. If you add a header (as I've done below), there is no issue.

library(gtsummary)
library(gt)
xxx <- mtcars |> 
  tbl_cross(row = vs, 
            col = am) |> 
  modify_header(label = "adding a header") |> 
  as_gt()
gtsave(xxx, "t1.docx")

Software version

> packageVersion("gtsummary")
[1] ‘1.7.2’
> packageVersion("gt")
[1] ‘0.10.1’

Word v16.83 on macOS 14.3.1

anddis avatar Mar 19 '24 18:03 anddis