r-markdown - 编织到 MS Word 时,波斯语/波斯语/阿拉伯语文本未显示在 Rmarkdown officedown/flextable 中

标签 r-markdown flextable farsi officedown

我正在使用 rmarkdown 以及两个有用的软件包(officedown 和 flextable)来生成 MS Word 文档。但是,当我用其他语言编写或将表的标题标签(使用 set_header_labels)更改为波斯语(使用 font(cs.family = "Arial Unicode MS", part = "header")),尽管它在 rmarkdown 查看器 Pane 中正确显示,但它不会将文本转换为 MS Word 中的正确形式(参见图片)。我测试了不同的字体,但问题仍然存在!我想知道是否有人对此有任何解决方案?谢谢。

这是一个可重现的示例:

---
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")

enter image description here

最佳答案

新版本的R与UTF-8更加兼容。

https://cran.r-project.org/bin/windows/base/NEWS.R-4.2.1.html

请更新您的 R,OS和软件包,然后重试。

这对我有用。

enter image description here

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

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=C                            
[3] 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     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9        digest_0.6.29     R6_2.5.1          officedown_0.2.4 
 [5] evaluate_0.15     zip_2.2.0         gdtools_0.2.4     cachem_1.0.6     
 [9] rlang_1.0.3       cli_3.3.0         uuid_1.1-0        xml2_1.3.3       
[13] rmarkdown_2.14    tools_4.2.1       officer_0.4.3     xfun_0.31        
[17] yaml_2.3.5        fastmap_1.1.0     compiler_4.2.1    systemfonts_1.0.4
[21] rvg_0.2.5         memoise_2.0.1     htmltools_0.5.2   knitr_1.39       
> 

关于r-markdown - 编织到 MS Word 时,波斯语/波斯语/阿拉伯语文本未显示在 Rmarkdown officedown/flextable 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72921988/

相关文章:

r - 安装自定义 TeX 包

r - 更改 RMarkdown 代码输出中错误消息的颜色(HTML、PDF)

java - 在旧的谷歌浏览器 gwt 表单设计中正确显示。但不支持 chrome 新版本 65.0.3325.162

android - 如何在 Android 中支持阿拉伯语文本?

java - 如何在 Android Studio 中编写波斯语?

R Markdown 图形分组以防止分页

rstudio - RPresentation 中的字体大小没有变化

r - flextable 中有条件的粗体值

java - 将 EditText 中的 unicode 波斯数字字符转换为 android 中的 double