rstudio / gt

Easily generate information-rich, publication-quality tables from R
https://gt.rstudio.com
Other
2.01k stars 204 forks source link

The new version of quarto misformats gt output in word documents, but only when the code chunk is labelled #1679

Closed jdjohn215 closed 1 month ago

jdjohn215 commented 4 months ago

Prework

Description

Tables in word documents created by Quarto are constrained to an extremely narrow width. This only happens when the code chunk creating the table is given a label, and it did not happen under the previous release of the Quarto CLI.

This may be an issue for Quarto, not gt, in which case I'll close this issue and submit it to the Quarto CLI maintainers.

Reproducible example

This quarto document creates the output shown in the following image.

---
format: docx
---

```{r}
#| label: setup
library(gt)
#| label: tbl-label
gt(iris[1:10,])

![image](https://github.com/rstudio/gt/assets/25727441/3e78de2a-db1e-434a-be12-53a353a35aa5)

## Expected result

I expected a word document like this one.

![image](https://github.com/rstudio/gt/assets/25727441/df22673a-8b81-40b0-ba46-bc6cc014e3c3)

I created that word document using this quarto document. The only difference is that I omitted the label from this code chunk.

format: docx

#| label: setup
library(gt)
gt(iris[1:10,])

## Session info

Here is the session info from inside a quarto run. I'm using quarto version 1.4.553.

R version 4.3.2 (2023-10-31) Platform: x86_64-apple-darwin20 (64-bit) Running under: macOS Sonoma 14.4.1

Matrix products: default BLAS: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRblas.0.dylib LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Chicago tzcode source: internal

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] gt_0.10.1

loaded via a namespace (and not attached): [1] digest_0.6.35 utf8_1.2.4 R6_2.5.1 fastmap_1.1.1
[5] tidyselect_1.2.1 xfun_0.43 magrittr_2.0.3 glue_1.7.0
[9] tibble_3.2.1 knitr_1.45 pkgconfig_2.0.3 htmltools_0.5.8.1 [13] generics_0.1.3 rmarkdown_2.26 dplyr_1.1.4 lifecycle_1.0.4
[17] xml2_1.3.6 cli_3.6.2 fansi_1.0.6 vctrs_0.6.5
[21] withr_3.0.0 compiler_4.3.2 rstudioapi_0.15.0 tools_4.3.2
[25] pillar_1.9.0 evaluate_0.23 yaml_2.3.8 rlang_1.1.3
[29] jsonlite_1.8.8

erinsteiner-NOAA commented 2 months ago

I'm curious if anyone has found a workaround to do the table cross-references without the messy table formatting?

olivroy commented 1 month ago

This is a Quarto issue. https://github.com/quarto-dev/quarto-cli/issues/7151 Not sure how we could work around this in gt. flextable seems to have done it. https://github.com/davidgohel/flextable.

Essentially, we could tweak our knit_print() method for word output in Quarto

Duplicate of https://github.com/rstudio/gt/issues/1604