Home > Back-end >  Executing Rscript from a Batch file - can't process "Umlaute" (ä, ö, ü) properly
Executing Rscript from a Batch file - can't process "Umlaute" (ä, ö, ü) properly

Time:10-27

I have an Rscript which executes just fine when i do it within RStudio. If i execute the same Rscript via a batch-file, it can't process the german "Umlaute" (ä, ö, ü).

  • The RScript is saved as UTF-8
  • The default text encoding is set to UTF-8
  • I tried adding CHCP 65001 and chcp 1252 to the batch-file, with same result, like this:
CHCP 65001
"C:/Users/John Doe/Documents/R/R-4.0.5/bin/Rscript.exe" "uebel.R"
pause

Is it a problem with batch? What can i do to avoid it?

In my case it wouldn't work to just remove all the "Umlaute". Technically, it would, but not practically.


Very simple example:

RScript, saved as "uebel.R":

übel <- 1 1

batch-file, saved as: "uebel.bat":

"C:/Users/John Doe/Documents/R/R-4.0.5/bin/Rscript.exe" "uebel.R"
pause

Gives the me Error in the cmd:

Fehler: unerwartete Eingabe in "ü" (Error: unexpected input in "ü")

Another example in the Rscript and what i receive in cmd:

cat("übelkeit")
übelkeit

CodePudding user response:

Try calling with

"C:/Users/John Doe/Documents/R/R-4.0.5/bin/Rscript.exe" --encoding="UTF-8" "uebel.R"

CodePudding user response:

I also know a solution for printing umlauts in R.

You should install the package ds4psy.

An example:

library(ds4psy)
cat (Umlaut["u"],"belkeit", sep = "")
übelkeit
  • Related