[R] Sweave special characters problem

Duncan Murdoch murdoch.duncan at gmail.com
Thu Jul 22 15:51:01 CEST 2010


On 22/07/2010 9:39 AM, Bunny, lautloscrew.com wrote:
> Sorry all,
>
> for not posting a minimal example. I am running R on Mac OS X snow leopard with Komodo edit / Sciviews-R. The problem is that the code does not work any more if there is an umlaut in my R code. The error message is some strange mixture of german and english, so this what the error message is supposed to look like:
> "Invalid multibyte character in Parser line 195" . Allan´s example works as a standalone, with his code I get the following error message. Maybe this is a mac problem ... 
>
> Error in parse(text = chunk) : 
>   Unexptected entry in "x <- data.frame(GeschÂ"
>   

That's a sign that you're running R with options("encoding") set to 
something other than UTF-8, but your input file is UTF-8.  It should be 
fine if, before running Sweave,
you run

options(encoding="UTF-8")

I don't know if this is possible using "R CMD Sweave", but you can 
always put together your own command line version using Rscript or "R 
--slave".

Duncan Murdoch
>
>
> Thx for any help in advance
>
> best 
>
> matt
>
>
>
>
> On 22.07.2010, at 14:47, Allan Engelhardt wrote:
>
> > A standalone example is always helpful.  The following works for me, so I am probably not understanding your problem:
> > 
> > ---[BEGIN: umlaut.Rnw]---
> > \documentclass[a4paper]{article}
> > \usepackage{ucs}
> > \usepackage[utf8x]{inputenc}
> > 
> > \begin{document}
> > 
> > <<test,echo=TRUE>>=
> > x <- data.frame(Geschäftslage=1:10)
> > summary(x)
> > @
> > \end{document}
> > ---[END: umlaut.Rnw]---
> > 
> > $ R CMD Sweave umlaut.Rnw
> > $ R CMD pdflatex umlaut.tex
> > $ gnome-open umlaut.pdf
> > 
> > Allan
> > 
> > 
> > On 22/07/10 13:19, Bunny, lautloscrew.com wrote:
> >> Dear all,
> >> 
> >> I use Sweave to create my reports. Unfortunately my script crashes whenever I my R code contains special characters like umlauts.
> >> Is there a way to to escape special characters in Sweave... This is the line that crashes Sweave:
> >> 
> >> gl_bybranch = ddply(new_wans,.(period,Branchen), function(X) data.frame(Geschäftslage=mean(X$sentiment)))
> >> 
> >> Unfortunately I can't just rename it, because I it´s displayed in the legend of graphics later on.
> >> 
> >> Thx for any suggestions!
> >> 
> >> best
> >> 
> >> matt
> >> 
> >> ______________________________________________
> >> R-help at r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>   
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list