[R] Sweave: R code in self defined TeX-commands

Martin Posch Martin.Posch at univie.ac.at
Fri Jun 25 11:54:41 CEST 2004


I need to produce a standard report for several variables in Sweave
and thus would need the possibility to define a TeX-command which includes 
R-code like

\newcommand{\meansd}[1]{The mean is \Sexpr{mean(#1)} and the standard 
deviation is  \Sexpr{sd(#1)} .
and then just write


in the latex code to get the whole sentence.

The above does not work, since Sweave ignores the \newcommand and does not 
expand the \statistics

Is there an alternative way to achieve this?

Martin Posch

Department of Medical Statistics
Medical University of Vienna
Schwarzspanierstr. 17, A-1090 Vienna
Tel.:  +43-1-4277-63205

More information about the R-help mailing list