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

Adding #| label: for tables in chunks messes up gt table formatting for docx #12022

Open
bjoernholzhauer opened this issue Feb 4, 2025 · 3 comments
Labels
bug Something isn't working docx Issues with the docx format tables Issues with Tables including the gt integration

Comments

@bjoernholzhauer
Copy link

Bug description

Whenever I try to reference tables and figures by adding something like #| label: tbl-example to a R chunk that produces a table using gt, I get an error message when opening the produced file with Word and it messes up the table formatting (columns becoming one character wide, lacking table dividing lines etc.).

Steps to reproduce

The following works without an issue

---
title: "Minimal example"
format: docx
number-sections: true
number-depth: 3
editor: source
execute:
  echo: false
tbl-cap-location: top
---
  
  
# Intro

<!-- In @tbl-example you see the numbers. -->

In the table below you see the numbers.

```{r}
#| tbl-cap: The numbers
library(gt)
data.frame(category=c("A", "B", "C"),
           numbers = 1:3) |>
  gt()
```  

It produces this:

Image

In contrast, this:

---
title: "Minimal example"
format: docx
number-sections: true
number-depth: 3
editor: source
execute:
  echo: false
tbl-cap-location: top
---
  
# Intro
In @tbl-example you see the numbers.
```{r}
#| tbl-cap: The numbers
#| label: tbl-example
library(gt)
data.frame(category=c("A", "B", "C"),
           numbers = 1:3) |>
  gt()
```  

runs without an error or warning, but when I try to open the resulting document wiht Word, I get

Image

and the table in the resulting document has messed up formatting (looks even worse in more complex tables):

Image

Expected behavior

Both example should essentially produce the same output, just one having a reference to the table.

Actual behavior

Error message about "Word found unreadale content..." and messed up table formatting.

Your environment

  • IDE RStudio 2024.09.1 Build 394
  • OS Microsoft Windows 11 Enterprise 10.0.26100 Buld 26100
  • R version 4.4.1 (2024-06-14 ucrt)
  • gt version gt_0.11.1

Quarto check output

quarto check
Quarto 1.5.57
[>] Checking versions of quarto binary dependencies...
      Pandoc version 3.2.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.41.0: OK
      Typst version 0.11.0: OK
[>] Checking versions of quarto dependencies......OK
[>] Checking Quarto installation......OK
      Version: 1.5.57
      Path: C:\local\RStudio-2024.09.1-394\resources\app\bin\quarto\bin
      CodePage: 1252

[>] Checking tools....................OK
      TinyTeX: (not installed)
      Chromium: (not installed)

[>] Checking LaTeX....................OK
      Tex:  (not detected)

[>] Checking basic markdown render....OK

[>] Checking Python 3 installation....(None)

      Unable to locate an installed version of Python 3.
      Install Python 3 from https://www.python.org/downloads/

[>] Checking R installation...........OK
      Version: 4.4.1
      Path: C:/Users/<*******ANONYMIZED*******>/AppData/Local/Programs/R/R-4.4.1
      LibPaths:
        - C:/Users/<*******ANONYMIZED*******>/AppData/Local/R/win-library/4.4
        - C:/Users/<*******ANONYMIZED*******>/AppData/Local/Programs/R/R-4.4.1/library
      knitr: 1.48
      rmarkdown: 2.28

[>] Checking Knitr engine render......OK


C:\Users\<*******ANONYMIZED*******>\OneDrive - <*******ANONYMIZED*******>>quarto check
Quarto 1.5.57
[>] Checking versions of quarto binary dependencies...
      Pandoc version 3.2.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.41.0: OK
      Typst version 0.11.0: OK
[>] Checking versions of quarto dependencies......OK
[>] Checking Quarto installation......OK
      Version: 1.5.57
      Path: C:\local\RStudio-2024.09.1-394\resources\app\bin\quarto\bin
      CodePage: 1252

[>] Checking tools....................OK
      TinyTeX: (not installed)
      Chromium: (not installed)

[>] Checking LaTeX....................OK
      Tex:  (not detected)

[>] Checking basic markdown render....OK

[>] Checking Python 3 installation....(None)

      Unable to locate an installed version of Python 3.
      Install Python 3 from https://www.python.org/downloads/

[>] Checking R installation...........OK
      Version: 4.4.1
      Path: C:/Users/<*******ANONYMIZED*******>/AppData/Local/Programs/R/R-4.4.1
      LibPaths:
        - C:/Users/<*******ANONYMIZED*******>/AppData/Local/R/win-library/4.4
        - C:/Users/<*******ANONYMIZED*******>/AppData/Local/Programs/R/R-4.4.1/library
      knitr: 1.48
      rmarkdown: 2.28

[>] Checking Knitr engine render......OK
@bjoernholzhauer bjoernholzhauer added the bug Something isn't working label Feb 4, 2025
@mcanouil
Copy link
Collaborator

mcanouil commented Feb 4, 2025

Could you update Quarto CLI to use the latest version? Thank you.
Also ensure you are using the latest version of gt/knitr and any dependencies related to your use case / issue.

@bjoernholzhauer
Copy link
Author

Is there any way to update Quarto CLI without downloading a msi from the quarto homepage? That is completely and utterly blocked by our corporate IT and it is unlikely that I could get an exception to this. I can wait until they approve and make available a new RStudio version that would come bundled with the latestr version (happens about once a year), but that puts things oddly out of sync with R package version (which I can update myself). I'm not sure, but I'd guess a lot of people in corporate settings might face a situation like this.

@mcanouil mcanouil added tables Issues with Tables including the gt integration docx Issues with the docx format labels Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working docx Issues with the docx format tables Issues with Tables including the gt integration
Projects
None yet
Development

No branches or pull requests

3 participants