Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue exporting tbl_cross object with gtsave #1609

Open
anddis opened this issue Mar 19, 2024 · 0 comments
Open

Issue exporting tbl_cross object with gtsave #1609

anddis opened this issue Mar 19, 2024 · 0 comments
Assignees

Comments

@anddis
Copy link

anddis commented Mar 19, 2024

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: ddsjoberg/gtsummary#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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants