I'm using rmarkdown and also two useful packages (officedown and flextable) to produce an MS word document. However, when I write in other languages or change the header label of tables (using set_header_labels
) to farsi (using font(cs.family = "Arial Unicode MS", part = "header")
), it does not transform the text to the correct form in MS word (see the picture) although it is correctly shown in the rmarkdown viewer pane. I tested different fonts but the problem persists! I'm wondering if anyone has any solutions to this? Thanks.
Here is a reproducible example:
---
output: officedown::rdocx_document
---
```{r message=F, warning=F, echo=F}
library(sysfonts)
library(flextable)
library(officedown)
library(dplyr)
library(extrafont)
iris %>% head() %>% flextable() %>% set_header_labels(Sepal.Length="طول کاسبرگ") %>%
font(j = 1, part = "header", fontname = "B Nazanin")
#you can choose other fonts like Arial Unicode MS too but it doesn't make any difference.
```
rmarkdown::render(input = paste0(getwd(),"/","ex.Rmd"), encoding="UTF-8")