Eva
Eva

Reputation: 917

Sweave how can I write R code inside the latex table environment?

I am working on Sweave now, when I want to use R code to describe one variable in the latex table.

It turns out that Sweave cannot read these R codes, the output is not the variable, instead, the output is the text form of all the code I write

Upvotes: 3

Views: 659

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226936

You may want \Sexpr{R expression}; for example, this Sweave snippet

<<echo=FALSE>>=
z <- exp(pi)
@

\begin{tabular}{cc}
  a & \Sexpr{z} \\
  b & \Sexpr{round(z,3)}  \\
\end{tabular}

becomes this when Sweaved (Swoven?)

\begin{tabular}{cc}
  a & 23.1406926327793 \\
  b & 23.141  \\
\end{tabular}

Upvotes: 5

Related Questions