# Utf8 encoding problems with knitr

I'm using RStudio 0.98.1102 on Windows 7 with knitr 1.10 (R 3.1.2) and tried to knit the following file:

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}

\begin{document}

ä ö ü Ä Ö Ü ß

<<>>=
options(encoding = "UTF-8")
runif(5)
@

\end{document}


which results in an "Package inputenc Error: Unicode char.. not set up for use with LaTeX" when running pdflatex over the resulting .tex file.

When I try knitting without the options() call, everything works.

I expected a behaviour the other way round and would appreciate an explanation.

• It looks as if with the option, knitr (or whatever is using the option) assumes that the start document is 8-bit encoded and converts it to utf8. – Ulrike Fischer Mar 6 '15 at 12:54
• Please do not use options(encoding = ...) unless you really understand what it means. In most cases, it is just the wrong thing to do (especially on Windows, of which the native encoding is not UTF-8). – Yihui Xie Mar 6 '15 at 14:26