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:

The following section gives some descriptive statistics. ä

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)

[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.

  • I agree with @richiemorrisroe. That being said, what is the encoding of the file you're trying to Sweave? I keep all my files in utf-8. Jul 14 '11 at 13:11
  • I thought of posting it here and not on a TeX related site because I don't think it is a TeX related problem. When I open the .tex file created by Sweave and change the NAs with the Umlauts, it compiles just fine. At least if I change [utf8] to [latin1] (I found that hint somewhere else). However, I still have the problem that Sweave replaces the Umlauts with NAs.
    – Christoph_J
    Jul 14 '11 at 15:42

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:

The following section gives some descriptive statistics. ä

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)

 [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            

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.

  • Great advice. But how does one do this? How do I change the locale?
    – Andrie
    Jul 14 '11 at 13:33
  • @Andrie OP is on Windows, which I'm not familiar with. Sys.setlocale() seems relevant and the R for Windows FAQ. I didn't add this info at the time because I am not familiar with the OS in question but your comment prompted me to take a peak... Jul 14 '11 at 14:51
  • @Gavin Simpson Thanks a lot, I guess that could be the answer. Unfortunately, I can't change my locale because of the issue mentioned here: Sys.setlocale() issue That was the reason I went for Sys.setlocale("LC_ALL", "C") in the first place. And since I am using English formatted dates in my analysis, I can't use my standard locale (which is the German one, I guess). As I mentioned, my Sweave file used to work, which lets me believe that the problem only occurred after I updated to R2.13.1.
    – Christoph_J
    Jul 14 '11 at 15:45
  • Thanks to the hints of @Gavin Simpson, @Roman Luštrik and @richiemorrisroe I came to the conclusion that this workaround might be the easiest solution: I manually add the Umlauts with \"a, \"u, etc in the Sweave file. Then the file compiles just fine. Thanks for your help!
    – Christoph_J
    Jul 14 '11 at 16:03

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.