I am just starting to learn Sweave (really neat tool). I am pretty
early in the learning curve (I had to think a moment ago whether a # or
% was the appropriate comment character).
I have successfully incorporated simple graphics and outputs, but am
having trouble getting a latex (xtable) table to function properly.
Latex is seemingly treating the xtable code as input or verbatim text.
That is, if I run Sweave('myfile.Snw', echo=T) I get the latex syntax
xtable code handed to me twice in the myfile.dvi. Turning echo off, I
get the xtable code (not the nicely formated latex table) back in the
dvi.
There seems nothing wrong with the myfile.tex file itself. (I attach a
snip below). Everything run fine if I manually edit the myfile.tex file
and delete the :
\begin{Schunk}
\begin{Soutput}
and,
\end{Soutput}
\end{Schunk}
commands. Dropping these, I get the properly formated latex table in
the dvi.
I see that others have used xtable, so I assume Sweave.sty handle xtable
ok.
What am I missing?
code and output chunks follow....
===snip====n<- xtable(final[,1:3])
@
\begin{tiny}
<< trial>>print(n)
@
\end{tiny}
\end{document}
===snip==
which produces
===snip==
\begin{tiny}
\begin{Schunk}
\begin{Soutput}
% latex table generated in R 1.8.1 by xtable 1.2-2 package
% Thu Jan 8 16:03:23 2004
\begin{table}[ht]
\begin{center}
\begin{tabular}{rrrr}
\hline
& shares & invested.sums & weighted.price \\
\hline
JBLU & 5.78 & 260.00 & 44.68 \\
IYR & 25.12 & 2395.00 & 94.48 \\
WM & 41.09 & 1565.00 & 38.00 \\
SPY & 37.27 & 3840.00 & 102.84 \\
IBM & 25.24 & 2130.00 & 83.45 \\
EWM & 177.20 & 1059.00 & 5.88 \\
KO & 25.61 & 1130.00 & 43.44 \\
EWJ & 230.00 & 1924.00 & 8.32 \\
DIA & 48.36 & 4295.00 & 89.06 \\
EWH & 123.16 & 1095.00 & 8.79 \\
QQQ & 98.12 & 2991.00 & 31.22 \\
IWZ & 78.03 & 2475.00 & 31.70 \\
IVE & 47.44 & 2158.00 & 45.36 \\
EWW & 73.39 & 1079.00 & 14.50 \\
IBB & 24.28 & 1390.00 & 58.28 \\
EWG & 67.07 & 879.00 & 12.93 \\
C & 62.81 & 2015.00 & 33.17 \\
TYC & 80.61 & 1325.00 & 16.80 \\
RHAT & 223.92 & 1425.00 & 6.89 \\
\hline
\end{tabular}
\end{center}
\end{table}
\end{Soutput}
\end{Schunk}
\end{tiny}
===snip==
Michaell
On Thu, 8 Jan 2004, michaell taylor wrote:> I have successfully incorporated simple graphics and outputs, but am > having trouble getting a latex (xtable) table to function properly. > Latex is seemingly treating the xtable code as input or verbatim text. > That is, if I run Sweave('myfile.Snw', echo=T) I get the latex syntax > xtable code handed to me twice in the myfile.dvi. Turning echo off, I > get the xtable code (not the nicely formated latex table) back in the > dvi. >A quick look through some of my Sweave files produced the snippet ------ The \code{xtable} package produces HTML and \LaTeX\ formatted tables <<echo=false,fig=false,results=tex>>library(xtable) data(tli) tli.table <- xtable(tli[1:10,]) digits(tli.table)[c(2,6)] <- 0 print(tli.table) @ ------- so it looks like results=tex is what you want. -thomas
pols1oh at bestweb.net wrote:> I am just starting to learn Sweave <snip>and> having trouble getting a latex (xtable) table to function properly. > Latex is seemingly treating the xtable code as input or verbatim text.The following is what I use for printing a table of a data.frame called 'ImportExport' <<results=tex>>xtable(ImportExport[1:6,1:6],type=tex,caption='First Six Variables') @ Inserting the "results=tex" in your code should do the trick, Cheers,> That is, if I run Sweave('myfile.Snw', echo=T) I get the latex syntax > xtable code handed to me twice in the myfile.dvi. Turning echo off, I > get the xtable code (not the nicely formated latex table) back in the > dvi. > > There seems nothing wrong with the myfile.tex file itself. (I attach a > snip below). Everything run fine if I manually edit the myfile.tex file > and delete the : > > \begin{Schunk} > \begin{Soutput} > > and, > > \end{Soutput} > \end{Schunk} > > commands. Dropping these, I get the properly formated latex table in > the dvi. > > I see that others have used xtable, so I assume Sweave.sty handle xtable > ok. > > What am I missing? > > code and output chunks follow.... > > ===snip====> n<- xtable(final[,1:3]) > @ > \begin{tiny} > << trial>>> print(n) > @ > \end{tiny} > \end{document} > ===snip==> > which produces > > ===snip==> > \begin{tiny} > \begin{Schunk} > \begin{Soutput} > % latex table generated in R 1.8.1 by xtable 1.2-2 package > % Thu Jan 8 16:03:23 2004 > \begin{table}[ht] > \begin{center} > \begin{tabular}{rrrr} > \hline > & shares & invested.sums & weighted.price \\ > \hline > JBLU & 5.78 & 260.00 & 44.68 \\ > IYR & 25.12 & 2395.00 & 94.48 \\ > WM & 41.09 & 1565.00 & 38.00 \\ > SPY & 37.27 & 3840.00 & 102.84 \\ > IBM & 25.24 & 2130.00 & 83.45 \\ > EWM & 177.20 & 1059.00 & 5.88 \\ > KO & 25.61 & 1130.00 & 43.44 \\ > EWJ & 230.00 & 1924.00 & 8.32 \\ > DIA & 48.36 & 4295.00 & 89.06 \\ > EWH & 123.16 & 1095.00 & 8.79 \\ > QQQ & 98.12 & 2991.00 & 31.22 \\ > IWZ & 78.03 & 2475.00 & 31.70 \\ > IVE & 47.44 & 2158.00 & 45.36 \\ > EWW & 73.39 & 1079.00 & 14.50 \\ > IBB & 24.28 & 1390.00 & 58.28 \\ > EWG & 67.07 & 879.00 & 12.93 \\ > C & 62.81 & 2015.00 & 33.17 \\ > TYC & 80.61 & 1325.00 & 16.80 \\ > RHAT & 223.92 & 1425.00 & 6.89 \\ > \hline > \end{tabular} > \end{center} > \end{table} > \end{Soutput} > \end{Schunk} > \end{tiny} > ===snip==> > Michaell > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html