简体   繁体   中英

How to handle encodings in knitr spin_child

Following recommendations on https://yihui.name/en/2018/11/biggest-regret-knitr , I started saving my .R files with UTF-8 encoding (using RStudios "Save with encoding"). Seems to work well, until it comes to using spin_child.

Under Windows, for example I have a file mainfile.R with this code:

print("Bär 1"); spin_child("subfile.R") 

subfile.R has this code:

print("Bär 2")

In RStudio under Windows, I run

rmarkdown::render("mainfile.R", encoding = "UTF-8")

If both files are saved with encoding UTF-8, Bär 1 comes out fine, but Bär 2 comes out as "Bär 2" (which seems like an encoding problem to me). Interestingly, if I change encoding of subfile.R to ISO-8859-1 (System default), both Bär come out correctly. It seems strange to me that I should have to use different encodings for different files, so I'm wonderning what I have to do if the input file for spin_child ist UTF-8 as well?

This is a bug in knitr , and I just fixed it on Github . Please try the development version and continue using UTF-8:

remotes::install_github('yihui/knitr')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM