2

I have some special characters in my UTF-8 .R file and the attempt to run code as a file in the R command line returns unexpected INCOMPLETE_STRING.

Meanwhile, the code runs okay line by line, say, in RStudio or Eclipse.

I suggest I need to change the locale via Sys.setlocale(locale=), but all my attempts (including SO's answers) to find the right locale parameter for UTF-8 gave OS reports request to set locale to "UTF-8" cannot be honored. I can set up something like Sys.setlocale(locale="English"), but it doesn't help.

How to set up "UTF-8" on Windows?

Anton Tarasenko
  • 8,099
  • 11
  • 66
  • 91

2 Answers2

2

I don't think you need to change to locale of your R to UTF-8 (if that is even possible under windows)

source(..., locale="UTF-8")

should do the trick. The R-script is then translated into your local locale.

Jan van der Laan
  • 8,005
  • 1
  • 20
  • 35
  • Thanks, but that returns `unexpected INCOMPLETE_STRING` to me. The error points at the line where non-ANSI characters appear first. – Anton Tarasenko Dec 13 '13 at 16:55
  • 1
    Right now I don't have access to a windows machine to et things on. However, I found the following answer that might help: http://stackoverflow.com/questions/5031630/how-to-source-r-file-saved-using-utf-8-encoding – Jan van der Laan Dec 15 '13 at 06:32
  • 2
    Thanks, Jan. This helped. I used `eval(parse(filename, encoding="UTF-8"))`, though it's just a workaround. – Anton Tarasenko Dec 15 '13 at 07:06
2

I had an issue with an R file encoded in UTF-8.

I fixed it by running the script this way :

Rscript --encoding=UTF-8 filename.R
Antoine Tissier
  • 621
  • 5
  • 13