davidgohel / flextable

table farming
https://ardata-fr.github.io/flextable-book/
558 stars 80 forks source link

"``{=openxml} [caption]" keeps showing up in docx output #455

Closed claytonperry closed 2 years ago

claytonperry commented 2 years ago

Hello! I'm running into an issue when trying to include captions on the flextables that I include in a Rmd I'm knitting to docx. Whenever I use the set_caption() function or 'tab.cap' option in the {r} chunk options I'm consistently seeing the caption included in a line that looks like "``{=openxml} [caption]" where the caption should be. Here's an example:

---
title: "Sample issue for docx output"
author: Clay Perry
Date: September 11, 2022
output: word_document
---
packages <- c("dplyr", "googlesheets4", "googledrive", "tidyr", "rmarkdown", "stringr", "knitr", "officedown", "flextable")

install.packages(setdiff(packages, rownames(installed.packages())), repos='http://cran.us.r-project.org')

#Call necessary packacges
lapply(packages, library, character.only = TRUE)

knitr::opts_chunk$set(echo=FALSE, warning=TRUE, message=FALSE, fig.cap=TRUE, tab.cap.style="Table Caption")
iris %>% 
    group_by(Species) %>%
    summarise(
        avg_sep_len = mean(Sepal.Length)
    ) %>%
    flextable() %>%
    set_caption(
        caption = "Average Sepal Length"
    )

and the docx that's output looks like this: image

I've searched for a long time now and can't find someone who's had the same issue - I did find something of a lead in documentation from MNazarov: LINK but I'm not sure how to proceed. Here's my 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 22000)

Matrix products: default

locale: [1] LC_COLLATE=English_United States.utf8 [2] LC_CTYPE=English_United States.utf8 [3] LC_MONETARY=English_United States.utf8 [4] 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] officer_0.4.4 officedown_0.2.4 rmarkdown_2.16 [4] flextable_0.7.3 huxtable_5.5.0 gt_0.7.0 [7] knitr_1.40 stringr_1.4.1 tidyr_1.2.0 [10] googledrive_2.0.0 googlesheets4_1.0.1 dplyr_1.0.9

loaded via a namespace (and not attached): [1] tidyselect_1.1.2 xfun_0.32 bslib_0.4.0 rematch2_2.1.2 [5] purrr_0.3.4 gargle_1.2.0 colorspace_2.0-3 vctrs_0.4.1
[9] generics_0.1.3 htmltools_0.5.3 yaml_2.3.5 base64enc_0.1-3 [13] utf8_1.2.2 rlang_1.0.5 jquerylib_0.1.4 pillar_1.8.1 [17] withr_2.5.0 glue_1.6.2 rappdirs_0.3.3 gdtools_0.2.4 [21] uuid_1.1-0 lifecycle_1.0.1 munsell_0.5.0 gtable_0.3.1 [25] cellranger_1.1.0 zip_2.2.1 memoise_2.0.1 codetools_0.2-18 [29] evaluate_0.16 fastmap_1.1.0 curl_4.3.2 fansi_1.0.3 [33] Rcpp_1.0.9 openssl_2.0.2 scales_1.2.1 cachem_1.0.6 [37] jsonlite_1.8.0 fs_1.5.2 systemfonts_1.0.4 askpass_1.1
[41] ggplot2_3.3.6 digest_0.6.29 stringi_1.7.8 grid_4.2.1 [45] cli_3.3.0 tools_4.2.1 magrittr_2.0.3 sass_0.4.2 [49] tibble_3.1.8 crayon_1.5.1 pkgconfig_2.0.3 ellipsis_0.3.2 [53] data.table_1.14.2 xml2_1.3.3 rvg_0.2.5 assertthat_0.2.1 [57] httr_1.4.4 rstudioapi_0.14 R6_2.5.1 compiler_4.2.1

I'm super grateful for any advice you have! And apologies if I didn't find the answer out there in my searching.

davidgohel commented 2 years ago

Please try to install the last version

claytonperry commented 2 years ago

That did it - my apologies. Not sure why I didn't already have 0.8.0, I only installed flextable for the first time last week. Thank you!

davidgohel commented 2 years ago

No problem, you had the previous version and that bug has been fixed with latest version that is on CRAN since today :)

github-actions[bot] commented 1 year ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.