gt icon indicating copy to clipboard operation
gt copied to clipboard

gtsave to docx doesn't render headers are bold or have footnote

Open szimmer opened this issue 3 years ago • 0 comments

Prework

  • [x ] Read and agree to the code of conduct and contributing guidelines.
  • [ x] If there is already a relevant issue, whether open or closed, comment on the existing thread instead of posting a new issue.
  • [ x] Post a minimal reproducible example so the maintainer can troubleshoot the problems you identify. A reproducible example is:
    • [x ] Runnable: post enough R code and data so any onlooker can create the error on their own computer.
    • [x ] Minimal: reduce runtime wherever possible and remove complicated details that are irrelevant to the issue at hand.
    • [x ] Readable: format your code according to the tidyverse style guide.

Description

Using gtsummary::tbl_summary -> gtsummary::as_gt and then saving using gt::gtsave to write to docx. I find that the headers don't render correctly. Originally, I thought it was footnotes causing an issue but that isn't it.

Reproducible example

  • [ x] Post a minimal reproducible example so the maintainer can troubleshoot the problems you identify. A reproducible example is:
    • [x ] Runnable: post enough R code and data so any onlooker can create the error on their own computer.
    • [x ] Minimal: reduce runtime wherever possible and remove complicated details that are irrelevant to the issue at hand.
    • [x ] Readable: format your code according to the tidyverse style guide.
library(gt)
library(gtsummary)

trial2 <- trial %>% select(trt, age, grade)
sumtab <- trial2 %>% tbl_summary()
sumtabnofoot <- sumtab %>% modify_footnote(all_stat_cols()~NA)

sumtab
sumtabnofoot

sumtab %>%
  as_gt() %>%
  gtsave("sumtab.docx")


sumtabnofoot %>%
  as_gt() %>%
  gtsave("sumtabnofoot.docx")

Produced document 1: image

Produced document 2: image

Expected result

Expected headings to be bolded and have a footnote in first example. Also expected some indentation to be present for sub categories.

Session info

R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8    LC_MONETARY=English_United States.utf8 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

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

other attached packages:
[1] gtsummary_1.6.1 gt_0.7.0       

loaded via a namespace (and not attached):
 [1] highr_0.9           pillar_1.8.0        compiler_4.2.1      forcats_0.5.1       tools_4.2.1         digest_0.6.29       evaluate_0.16       lifecycle_1.0.1    
 [9] tibble_3.1.8        gtable_0.3.0        pkgconfig_2.0.3     rlang_1.0.4         reprex_2.0.1        DBI_1.1.3           cli_3.3.0           rstudioapi_0.13    
[17] commonmark_1.8.0    yaml_2.3.5          xfun_0.32           fastmap_1.1.0       withr_2.5.0         xml2_1.3.3          dplyr_1.0.9         stringr_1.4.0      
[25] knitr_1.39          fs_1.5.2            sass_0.4.2          generics_0.1.3      vctrs_0.4.1         grid_4.2.1          tidyselect_1.1.2    glue_1.6.2         
[33] R6_2.5.1            processx_3.7.0      fansi_1.0.3         rmarkdown_2.14      callr_3.7.1         clipr_0.8.0         ggplot2_3.3.6       purrr_0.3.4        
[41] tidyr_1.2.0         magrittr_2.0.3      ps_1.7.1            scales_1.2.0        htmltools_0.5.3     ellipsis_0.3.2      broom.helpers_1.8.0 assertthat_0.2.1   
[49] colorspace_2.0-3    utf8_1.2.2          stringi_1.7.8       munsell_0.5.0       crayon_1.5.1    

szimmer avatar Sep 15 '22 14:09 szimmer