1

I'm trying to use a UTF-8 encoded .Rnw file in combination with xelatex in RStudio. Since xelatex uses native UTF-8 support i cannot use

\usepackage[utf8]{inputenc}

in my .Rnw file, which would ensure that the encoding auto-guessing of Sweave() works properly. The only other option I know of is to run

Sweave(..., encoding="utf8")

however, I don't know how to configure RStudio to call Sweave() that way. Is there an option in RStudio for that, or any other way to pre-set this option for Sweave?

1

Although Sweave guesses the file encoding from \usepackage[foo]{inputenc}, RStudio does not guess, because it is an editor, and it knows the encoding precisely. In fact, RStudio just passes the encoding to utils::Sweave() directly, so you are totally fine without \usepackage[utf8]{inputenc} when using XeLaTeX. You need to make sure you are using the latest version of RStudio, since I do not remember which version of RStudio this feature was added to (but I'm pretty sure the latest version has it). The same thing is applied to knitr, which does not guess the encoding at all.

  • indeed it passes that correctly, thanks! Sneaked in some ad for your tool, ha? :-) totally have to take a look at that. Still stuck btw, doing utf-8 stuff in R on windows seems to be kind of a bad idea due to windows and locales... :-( – barbaz Aug 7 '13 at 19:41
  • @barbaz yes, ads added because I think it is a bad idea to guess the encoding; you are also right that Windows is the hell of encodings. – Yihui Xie Aug 7 '13 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.