rmarkDown主持人:循环循环,包含UTF-8编码的弹力
是否可以在包含UTF-8编码的可弹力的循环中包括一个子文件?
这是我的yaml:
---
output: officedown::rdocx_document
---
如果不使用循环,它可以完美工作,而delta(“ \ u0394”)在输出文件中正确显示:
```{r, echo = FALSE, message = FALSE}
library(flextable)
# Create columns
col1 <- c("a", "\U0394")
col2 <- c(1.0, 2.0)
# Create dataframe
data <- data.frame(Parameter = col1,
Value = col2)
# Create flextable
ft <- flextable(data)
ft
```
要循环通过此flextable,我将上面的代码保存为子文件,并将其包含在一个中ASIS-chunk带有 knit_child()
...
```{r, echo = FALSE, message = FALSE, results = "asis"}
library(rmarkdown)
library(knitr)
library(flextable)
# Read child doc two times
for (i in 1:2){
out <- knit_child("path_to_child\\child.Rmd", quiet = TRUE)
cat(out)
cat("\n\n")
}
```
...但随后得到此错误,因为UTF-8编码已不再识别:
Error in read_xml.character(file) : error parsing attribute name [68]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在循环中使用“ \ u226570”的经验。这是由于系统语言环境的各个方面。遵循以下内容:
sessionInfo()
并检查语言环境信息。sys.setlocale(“ lc_all”,“ English_united States.utf8”)
来执行此操作。我认为您的问题将在设置有效的UTF-8语言环境后得到解决。
I had the same experience using "\u226570" inside a loop. It is due to the aspects of your system locale. Follow this:
sessionInfo()
and check the locale information.Sys.setlocale("LC_ALL","English_United States.utf8")
.I think your problem would be resolved after setting a valid UTF-8 locale.
您需要使用
flextable_to_rmd
。请参阅:
您必须在“ path_to_to_to_to_to_to_child/child.rmd”:
You need to use
flextable_to_rmd
.See:
You have to slightly adjust the code in "path_to_child/child.Rmd":