[R] Sweave problem, with multicolumn tables from R to LaTeX

Ista Zahn istazahn at gmail.com
Thu Apr 9 14:50:46 CEST 2009


Hi Christian,
I've been having this problem as well. There are bug reports about
this (one of them mine):
http://biostat.mc.vanderbilt.edu/trac/Hmisc/ticket/25
http://biostat.mc.vanderbilt.edu/trac/Hmisc/ticket/28
so hopefully the developers are aware of the problem and will address
it in the next release.


By the way: what do you need the xtable library for? I see that you
loaded it, but never call any of the functions in your example code.

All the best,
Ista
From: Christian Salas <christian.salas at yale.edu>
To: r-help at r-project.org
Date: Wed, 08 Apr 2009 12:05:34 -0400
Subject: [R] Sweave problem, with multicolumn tables from R to LaTeX
Hi there,

I have been using the example provided bellow for a while, and It was
working without any problem. Nevertheless, just since 2-3 days is not
working, probably because I did update.packages(). I have tried to
re-install the older versions of the packages Hmisc() and xtable(),
but still does not work. Can you run this example, and tell me if you
got the same problems?

I use linux-ubuntu, and R 2.8.1

Here is my .Rnw file

%%%%%%%
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{Sweave}
\SweaveOpts{echo=TRUE}

\title{Why is not working this? a table from R having multi columns
names}
\author{Myself}
\date{\today}

\begin{document}
\maketitle

<<label=my.load.fx,keep.source=T>>=
#Calling some packages
library(Hmisc)
library(xtable)

#version of the packages
packageDescription('Hmisc')$Version #version of Hmisc
packageDescription('xtable')$Version  #version of xtable

#version and features of my PC and R
R.version$platform
R.version$version.string
@

\section{The table ready to be exported}
An R table as an example.
<<>>=
tab.coef.allmodels <-
structure(c(246.8809, 153.6952, 43.6259, 1823.686, -4.0138, -53.8741,
-13.9552, -699.7154, 0, -3.0084, -0.5188, -41.7249, 4.0898,
2.0342, 0.2798, 25.636, 235.5128, 160.0244, 30.0147, 1523.0723,
3.7601, -53.9238, -3.9789, -597.1446, 0, -3.2745, -0.0025, -28.7418,
4.4203, 2.1606, 0.0124, 17.9259), .Dim = c(4L, 8L), .Dimnames = list(
   c("NHA", "GHA", "Hdom", "VHA"), c("Intercept", "stand2",
   "band3", "band7", "Intercept", "stand2", "band3", "band7"
   )))
tab.coef.allmodels
@

\section{Producing the \LaTeX\ table}
\subsection{Showing a simple output table, but not being
 the aimed one}

The following syntax produce Table \ref{tab:coefAllmod1}, which is not
what I want.
<<label=tab1>>=
l <- latex(tab.coef.allmodels, file="tab.coefAllmod1.tex",
rowlabel="Model for",
     first.hline.double=FALSE,
     rowlabel.just="l",
caption="MLR and LME parameter estimates by stand variables",
     caption.loc="top", label="tab:coefAllmod1",where="!h")
@

\input{tab.coefAllmod1}


\subsection{What I want, but not getting it right}
The following syntax produce Table \ref{tab:coefAllmod2}, which
contains all the information that i want, but is not giving me
the correct format.
<<label=tab2>>=
l <- latex(tab.coef.allmodels, file="tab.coefAllmod2.tex",
rowlabel="Model for",
     first.hline.double=FALSE,
     rowlabel.just="l",
    cgroup=c("MLR","LME"),
    n.cgroup=c(4,4),
caption="MLR and LME parameter estimates by stand variables",
     caption.loc="top", label="tab:coefAllmod2",where="!h")
@

\input{tab.coefAllmod2}

I have been using this
syntax for a while, and was working without any problem.
 Nevertheless, just since 2-3 days is not working, probably
 because I did {\tt update.packages()}.
 I have tried to re-install the older versions of the packages
 {\tt Hmisc()} and {\tt xtable()}, but still does not work.

\vspace{1in}
{\Large   {\bf What Am I missing here?}}

\end{document}

%%%%%%%

The the main .tex file, tables, the ouput pdf, and the .Rnw files are
in the following url, if you want to check them

http://environment.yale.edu/salas/questions/shortTable/multcolTable_short.tex
http://environment.yale.edu/salas/questions/shortTable/tab.coefAllmod1.tex
http://environment.yale.edu/salas/questions/shortTable/tab.coefAllmod2.tex
http://environment.yale.edu/salas/questions/shortTable/multcolTable_short.pdf
http://environment.yale.edu/salas/questions/shortTable/multcolTable_short.Rnw

thanks in advance for your help

-- 
-------------------------------------------------------------------------------
Christian Salas                     E-mail:christian.salas at yale.edu
PhD candidate                       http://environment.yale.edu/salas
School of Forestry and Environmental Studies
Yale University                     Tel: +1-(203)-432 5126
360 Prospect St                     Fax:+1-(203)-432 3809
New Haven, CT 06511-2189            Office: Room 35, Marsh Hall
USA

Yale Biometrics Lab                  http://environment.yale.edu/biometrics




More information about the R-help mailing list