[Tex/LaTex] Sweave only produces NAs when using Umlauts.

rsweave

I have a problem with Sweave. As soon as I use any mutated vowels/Umlauts (ü, ä, etc.) Sweave produces an NA in the document although it worked before. I don't know what to do, so any help would be greatly appreciated.

Here is an example of a Test.Rnw file:

\documentclass[a4paper]{article}
\usepackage[latin1]{inputenc}
%aä
\begin{document}
The following section gives some descriptive statistics. ä
\end{document}

Although the file is produced, it only includes two NAs.

Also, I get the following warning message:

Warning message:
running command '"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\texi2dvi.exe" --quiet --pdf     "First_Paper_Test.tex"  -I "C:/Program Files/R/R-2.13.1/share/texmf/tex/latex" -I   "C:/Program Files/R/R-2.13.1/share/texmf/bibtex/bst"' had status 1 

If I delete the Umlauts, I do not have a problem at all. Also, if I add further paragraphs without umlauts, those paragraphs show up just fine. My sessionInfo():

R version 2.13.1 (2011-07-08)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] tools_2.13.1

I'm running Windows 7.

Best Answer

Your R is running in a C locale, not a UTF-8 locale. As R has to parse and update the file, I'm not surprised it doesn't know what to do with those characters. Try running Sweave/R in a UTF-8 locale and see if that helps.

For example, Sweave-ing your file from within R produces:

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
%aä
\usepackage{Sweave}
\begin{document}
The following section gives some descriptive statistics. ä
\end{document}

where my R is running in:

> sessionInfo()
R version 2.13.1 Patched (2011-07-08 r56332)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
 [5] LC_MONETARY=C              LC_MESSAGES=en_GB.UTF-8   
 [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
 [1] tools     grid      splines   stats     graphics  grDevices utils    
 [8] datasets  methods   base     

other attached packages:
[1] pscl_1.03.10     vcd_1.2-9        colorspace_1.0-1 gam_1.04        
[5] coda_0.14-2      lattice_0.19-23  mvtnorm_0.9-96   MASS_7.3-13

To see the current locale use Sys.getlocale() and to set a new locale use Sys.setlocale(). Also, see section 3 of the R for Windows FAQ and links to other areas of the FAQ therein. There is also a small amount of info in the R Installation & Administration Manual.