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

Chunk labeled with tbl- which outputs a gt table with a tab_spanner generates an invalid docx file #1934

Open
2 tasks done
raffaem opened this issue Dec 21, 2024 · 0 comments
Assignees

Comments

@raffaem
Copy link

raffaem commented Dec 21, 2024

Prework

Description

This is a spin-off of #1898 focused on chunks labeled as a table.

If you write a chunk labeled as a table for cross-references purpose (that is, #| label: tbl-SOMETHING), and you output a gt table with a tab spanner, the resulting docx file is invalid.

It won't even open in Microsoft Word for Windows, it will say the document contains unreadable content:

Image

Reproducible example

---
title: "test"
format: docx
---

```{r}
#| label: tbl-reg
#| echo: false
#| output: true
library(gt)
tbl_comp_names <- structure(list(lvl = c("BEBRAS", "Advent of code"), 
                                 per = c(79.5,
                                         37.2), 
                                 per_grand = c(57.4, 26.9), 
                                 grandtotal = c(108L, 108L), 
                                 total = c(78L, 78L)), 
                            row.names = c(NA, -2L), 
                            class = c("tbl_df", 
                                      "tbl", "data.frame"))

tbl_comp_names %>% 
  gt() %>%
  tab_spanner(
    columns = starts_with("per"),
    label=("percentage")) %>%
  tab_spanner(
    columns = ends_with("total"),
    label=("n"))

Expected result

The docx file should be valid

Session info

> sessionInfo()
R version 4.4.2 (2024-10-31)
Platform: x86_64-pc-linux-gnu
Running under: Arch Linux

Matrix products: default
BLAS:   /usr/lib/libblas.so.3.12.0 
LAPACK: /usr/lib/liblapack.so.3.12.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_DK.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Europe/Rome
tzcode source: system (glibc)

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

other attached packages:
[1] gt_0.11.1

loaded via a namespace (and not attached):
 [1] digest_0.6.37     R6_2.5.1          fastmap_1.2.0     tidyselect_1.2.1  xfun_0.49        
 [6] magrittr_2.0.3    glue_1.8.0        tibble_3.2.1      knitr_1.49        parallel_4.4.2   
[11] htmltools_0.5.8.1 pkgconfig_2.0.3   dplyr_1.1.4       generics_0.1.3    lifecycle_1.0.4  
[16] xml2_1.3.6        cli_3.6.3         sass_0.4.9        vctrs_0.6.5       withr_3.0.2      
[21] compiler_4.4.2    rstudioapi_0.17.1 tools_4.4.2       evaluate_1.0.1    pillar_1.10.0    
[26] rlang_1.1.4   
@raffaem raffaem changed the title tbl chunk with tab_spanner generate invaliddocx file Chunk labeled with tbl- which outputs a gt table with a tab_spanner generates an invalid docx file Dec 21, 2024
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