[R] Apparent conflict between \Sexpr in Sweave and R2HTML

Scott Waichler
Mon, 05 Jul 2004 16:08:38 -0000

I have come across an apparent bug in the operation of Sweave.  If I
load the package R2HTML then execution of \Sexpr{} in an *.Rnw file no
longer works.  The \Sexpr{} code is simply written to the *.tex file.
Below are my *.Rnw file, commands, and output.

The Sweave file, Sweave-test-1_short.Rnw:

% -*- mode: noweb; noweb-default-code-mode: R-mode; -*-
\documentclass{article}
\title{A Test File}
\author{Friedrich Leisch}
\SweaveOpts{echo=FALSE}
\begin{document}
\maketitle
Now we look at Gaussian data:
<<>>library(stats)
x <- rnorm(20)
print(x)
print(t1 <- t.test(x))
@
Note that we can easily integrate some numbers into standard text: The
third element of vector \texttt{x} is \Sexpr{x[3]}, the
$p$-value of the test is \Sexpr{format.pval(t1$p.value)}. % $
\end{document}


My commands:
> R.version.string
[1] "R version 1.9.1, 2004-06-21"
> library(R2HTML)

Loading R2HTML package...
> Sweave("Sweave-test-1_short.Rnw")
Writing to file Sweave-test-1_short.tex
Processing code chunks ...
 1 : term verbatim

You can now run LaTeX on Sweave-test-1_short.tex
>


The Sweave output file, Sweave-test-1_short.tex:

% -*- mode: noweb; noweb-default-code-mode: R-mode; -*-
\documentclass{article}
\title{A Test File}
\author{Friedrich Leisch}

\usepackage{/usr/lib/R/share/texmf/Sweave}
\begin{document}
\maketitle
Now we look at Gaussian data:
\begin{Schunk}
\begin{Soutput}
 [1] -1.80980347  1.41215325 -0.01118795  1.69149919  0.04621916  0.43672840
 [7]  0.05831105  1.26632742  0.41980267 -0.45035200 -0.73382409 -0.92390546
[13]  0.28338334 -0.05982873 -0.15500443 -2.43182528 -0.69751187 -0.30238204
[19]  0.99555389 -1.80047878
\end{Soutput}
\begin{Soutput}
	One Sample t-test

data:  x
t = -0.5728, df = 19, p-value = 0.5735
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
 -0.6436499  0.3670373
sample estimates:
 mean of x
-0.1383063
\end{Soutput}
\end{Schunk}
Note that we can easily integrate some numbers into standard text: The
third element of vector \texttt{x} is \Sexpr{x[3]}, the
$p$-value of the test is \Sexpr{format.pval(t1$p.value)}. % $
\end{document}



Scott Waichler
Pacific Northwest National Laboratory
Richland, Washington USA
scott.waichler at pnl.gov