[R] Sweave produces gibberish instead of apostrophe in pdf

Gavin Simpson gavin.simpson at ucl.ac.uk
Wed Feb 27 11:48:28 CET 2008


On Wed, 2008-02-27 at 11:35 +0100, Paul Hiemstra wrote:
> Dear All,
> 
> I try to use Sweave to make a document. But when I use the Sweave() 
> command on it and build a pdf with pdflatex (3.141592-1.40.3) my 
> apostrophes are replaced by some gibberish (an 'a' with a hat on it, a 
> capital A with a arc pointing upwards on it and a capital Y with two 
> points on it). If I manually replace the apostrophes using the keyboard, 
> I get a different looking apostrophe and the output is correct.
> 
> I'm using Debian Linux (Lenny) with TexLive, Kile and R 2.6.1.

I presume that R is running in a UTF-8 locale on your Debian box (or
some other locale that is different to the one pdflatex is working in);
the fancy quotes used in some print methods in R aren't available in all
locale/font encodings and these get interpreted as the "gibberish" you
are seeing.

Stick this in your preamble and see if it works (you might need to
install a TexLive package from your usual Debian repository to get this
[LaTeX] package installed):

\usepackage[utf8x]{inputenc}

it did for me on my Fedora box when I first came across this issue.

HTH

G

> 
> This is a sample, the problem is in the lm output in the "Signif. codes" 
> line:
> 
> \documentclass[a4paper,10pt]{article}
> \title{Spam}
> \author{F. Bar}
> 
> \begin{document}
> <<reg>>=
> n <- 50
> x <- seq(1, n)
> a.true <- 3
> b.true <- 1.5
> y.true <- a.true + b.true * x
> s.true <- 17.3
> y <- y.true + s.true * rnorm(n)
> out1 <- lm(y ~ x)
> summary(out1)
> @
> \end{document}
> 
> And the resulting .tex file:
> 
> \documentclass[a4paper,10pt]{article}
> \title{Spam}
> \author{F. Bar}
> 
> \usepackage{Sweave}
> \begin{document}
> \begin{Schunk}
> \begin{Sinput}
>  > n <- 50
>  > x <- seq(1, n)
>  > a.true <- 3
>  > b.true <- 1.5
>  > y.true <- a.true + b.true * x
>  > s.true <- 17.3
>  > y <- y.true + s.true * rnorm(n)
>  > out1 <- lm(y ~ x)
>  > summary(out1)
> \end{Sinput}
> \begin{Soutput}
> Call:
> lm(formula = y ~ x)
> 
> Residuals:
> Min 1Q Median 3Q Max
> -31.9565 -9.4745 -0.1708 7.3759 44.6538
> 
> Coefficients:
> Estimate Std. Error t value Pr(>|t|)
> (Intercept) -0.07386 4.64712 -0.016 0.987
> x 1.57405 0.15860 9.924 3.25e-13 ***
> ---
> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 .’ 0.1 ‘ ’ 1
> 
> Residual standard error: 16.18 on 48 degrees of freedom
> Multiple R-Squared: 0.6723, Adjusted R-squared: 0.6655
> F-statistic: 98.49 on 1 and 48 DF, p-value: 3.245e-13
> \end{Soutput}
> \end{Schunk}
> \end{document}
> 
> cheers and thanks for any help,
> Paul
> 
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list