[R] Sweave \Sexpr{} advice please

Dieter Menne dieter.menne at menne-biomed.de
Sun May 10 09:45:46 CEST 2009


Kyle Matoba <kmmatoba <at> ucdavis.edu> writes:

> A question in my work I use \Sexpr{} statements scalar values and the xtable
> package for all manner of tables.  What I'd like to do is to use a vector
> inline, rather than a whole separate table.   Something like:
> 
> % Sweave block:
> <<>>=
> covmat <- cov(matrix(runif(100),ncol=3))
> @
> 
> % back to Latex, typing up a report, my homework, etc.
> The first column of the covariance matrix is $(\Sexpr{covmat[1,1]},
> \Sexpr{covmat[2,1]}, \Sexpr{covmat[3,1]})^T$
> 

To unclutter the text in Sexpr, I normally prepare the results in the 
Sweave block in advance

Dieter

covmat <- cov(matrix(runif(30),ncol=3))
ft = paste(round(covmat[,3]),collapse=", ")
ft
named = c(Val=3,StdDev=4,p=0.4)
ft = paste(names(named),named,sep="= ",collapse=", ")
ft




More information about the R-help mailing list