Is it possible to include a child document in a loop that contains a flextable with UTF-8 encoding?
This is my YAML:
---
output: officedown::rdocx_document
---
Without using a loop, it works perfectly and the Delta ("\U0394") is displayed correctly in the output file:
```{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
```
To loop over this flextable, I saved the code above as a child file and included it in an asis-chunk with 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")
}
```
...but then get this error, because the UTF-8 encoding is somehow not recognized anymore:
Error in read_xml.character(file) : error parsing attribute name [68]
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.