davidgohel / flextable

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

some but not all unicode letters not displayed in RMarkdown when used with knit_print, run_autonum, and flextable_to_rmd #470

Closed mlindner00120 closed 2 years ago

mlindner00120 commented 2 years ago

Hi, some but not all unicode letters are not displayed in RMarkdown incorrectly when used with nit_print, run_autonum, and flextable_to_rmd. This similar to the problem mentioned here: https://github.com/davidgohel/flextable/issues/268

The average sign \u00F8 is always displayed correctly, but not the Greek letter tau or the less than equal sign <=. If I don't use run_autonum, cat(knit_print(tab)) or flextable_to_rmd and just write "tab", the characters are displayed correctly. Do you have any solution?

This is my code,:

---
title: "Title"
output:
  officedown::rdocx_document:
    mapstyles:
      Normal: ['First Paragraph']
mainfont: "Calibri" 
sansfont: "Calibri"
monofont: "Calibri" 
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(dplyr, warn.conflicts = F)
library(flextable)
library(greekLetters)
library(rmarkdown)
library(officedown)
library(knitr)
library(officer)

df <- c(1:4)
df <- matrix(df,2,2)
df <- as.data.frame(df)
tab <- autofit(flextable(df)) %>%
compose(part = "b", i = 1, j = 1, value = as_paragraph("tau ", greeks("tau")," (Greek letter)")) %>%
compose(part = "b", i = 2, j = 1, value = as_paragraph("average \u03C4(Unicode)")) %>%
compose(part = "b", i = 1, j =2, value = as_paragraph("tau \u00F8",greeks("tau"),"  (Unicode)")) %>%
compose(part = "b", i = 2, j =2, value = as_paragraph("less then equal \u2264","(Unicode)")) %>%
# not successfull
set_caption(caption = paste0("average sign \u2264"),run_autonum(seq_id = "tab"))
            cat(knit_print(tab))
# successfull:
# tab

My sessionInfo is:

R version 4.0.5 (2021-03-31) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19043)

Matrix products: default

locale: [1] LC_COLLATE=English_Switzerland.1252 LC_CTYPE=English_Switzerland.1252 LC_MONETARY=English_Switzerland.1252 [4] LC_NUMERIC=C LC_TIME=English_Switzerland.1252

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

other attached packages: [1] officer_0.4.4 knitr_1.40 officedown_0.2.4 rmarkdown_2.16 greekLetters_0.0.7 flextable_0.7.2
[7] dplyr_1.0.8

loaded via a namespace (and not attached): [1] zip_2.2.0 Rcpp_1.0.8.3 pillar_1.8.1 compiler_4.0.5 base64enc_0.1-3 tools_4.0.5
[7] digest_0.6.29 uuid_1.1-0 jsonlite_1.8.0 evaluate_0.16 memoise_2.0.1 lifecycle_1.0.1
[13] tibble_3.1.6 pkgconfig_2.0.3 rlang_1.0.2 cli_3.2.0 curl_4.3.2 yaml_2.3.5
[19] xfun_0.30 fastmap_1.1.0 stringr_1.4.1 xml2_1.3.3 equatags_0.2.0 gdtools_0.2.4
[25] generics_0.1.3 vctrs_0.4.1 systemfonts_1.0.4 tidyselect_1.1.2 glue_1.6.2 data.table_1.14.2 [31] R6_2.5.1 rvg_0.2.5 fansi_1.0.3 purrr_0.3.4 magrittr_2.0.3 ellipsis_0.3.2
[37] htmltools_0.5.2 xslt_1.4.3 assertthat_0.2.1 V8_4.1.0 katex_1.4.0 utf8_1.2.2
[43] stringi_1.7.6 cachem_1.0.6



Thanks in advance!
davidgohel commented 2 years ago

As explained in the comment you linked, there's not much I can do.

The new version of R (I think since R >= 4.2) is managing the UTF-8. Could you update your R version and try? See https://developer.r-project.org/Blog/public/2021/12/07/upcoming-changes-in-r-4.2-on-windows/

FYI, it works perfectly on my machines (UTF-8):

Capture d’écran 2022-10-06 à 12 29 00
mlindner00120 commented 2 years ago

Hi, thanks for your answer. We have to think about how to deal with that but at least it's again clearer where the problem could lie.

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.