UTF-8 with R Markdown, knitr and Windows

What?

The file .Rmdis displayed without errors through knitr(or rmarkdown) inside Linux. Related material (i.e. child R scripts and CSV input) is set to UTF-8 .

Running the same script from within Windows (in fact, the script is inside the cloned git repository) does not display all characters cleanly, since it is installed in Windows-1252 .

Examples

For example, a row "sans réserves"obtained from CSV into some contents of the data.frame column is typed as "sans réserves". To read this correctly, just add encoding='UTF-8'in read.csv, obviously, when reading data.

Another example that relates to writing among other lines of code Ris a line "Trésorier Général". He is typed like "Trésorier Général". Fortunately the next tip

read_chunk(lines = readLines("TestSpanishText.R", encoding = "UTF-8"))

taken from https://stackoverflow.com/a/3/93829/... works, and the line displays as expected.

Related

[ Update ] There are some related Q & As questions, but they are over 2-3 years old. In addition, this page https://support.rstudio.com/hc/en-us/articles/200532197-Character-Encoding points to the problem itself.

Questions

Is there another, simpler way to overcome this problem with regards to UTF-8and Windows inside R? Recommendations on how to approach this problem? I try to follow one source for the whole principle.

ps- : https://superuser.com/a/221602/128768

+4

Source: https://habr.com/ru/post/1651691/


All Articles