Umlauts are not printed correctly when printed into document

350 views Asked by At

When printing a word file with the print() command, umlauts (ä,ö,ü) are not being printed correctly into the word file.

My R Studio is setup to save scripts as UTF-8. I manually saved all files "encoded as UTF-8", after I find/replaced all umlauts with ae/oe/ue and back to ä/ö/ü again. The officer package is set to use UTF-8.

Is there another setting (maybe in R itself) that has to be checked for successfull endocing when printing into a docx file?

EDIT:

I found the solution: I was running the scripts with the source command, which doesn't have UTF-8 set as default. This prints the umlauts (officer, .doxc)

source("path/to/script.R", encoding = "UTF-8" )

This one doesnt:

source("path/to/script.R", sep = ""))
1

There are 1 answers

3
Snot On

It happens when r is dealing with non-english language.

Since I don't know your exact code,

1). I suggest that you may try Sys.setlocale(category = "LC_ALL", locale = "")

Set the locale to one that contains umlauts.

2). Also, you may update your Rstudio to the latest version and then try:

Open: (Menu bar) Tools-> Global Options-> Code (left bar) -> Saving

Set the default text encoding to proper one (UTF-8 for example)