Encoding in Rstudio fails in Windows Task Scheduler

I have been unable to solve the mystery why the encoding works properly when running a script manually but it doesnt when calling that same script via the task scheduler.

Any advise here?

What do you mean by "the encoding"?

When it fails in the task scheduler, does it fail to start, or runs for a bit and then fails? Do you have an error message somewhere?

When running in the task scheduler, are the logs (the output of the R script) stored somewhere?

Can you run a very simple R script, e.g. Rscript.exe -e "cat('success')" in the command line and in the task scheduler, and make sure this runs? You may also use where Rscript.exe to make sure the right version of R is called.

No the problem is that any sort of action on a variable that contains ö,é,ä,ü and so on will not work. This means for example if I try to filter in a script smth like this:

df = data[col1 = "Presäntation]

this wont work since the "ä" wont be read as "ä" but ae. But the dataframe data actually contains varibles named with "ä".

This works manually triggering the script but when doing it via the scheduler it just doesnt read ä as ä but ae.

Hmm, can't reproduce.

I created a csv with:


and a script with:

df <- read.csv("C:/Users/me/tmp/bla.csv")
writeLines(colnames(df), con = "C:/Users/me/tmp/out.log")

And when running through the task scheduler I get the correct output in out.log:


So I suspect it's a more complicated case, where the file itself may not be UTF8 or an older OS? On my Windows 11, getOption("encoding") gives native.enc and Sys.getlocale("LC_CTYPE") gives "English_United States.utf8" no matter if I start from command line or Task Scheduler.

Can you give more details on your OS version, the encoding of the file to read, and the R command you use to read the file? Does it help if you first ensure the file is UTF8?