[R] latex(Hmisc): cgroup + rownames shifts column names

Michael Erickson erickson at ucr.edu
Thu Apr 23 21:16:41 CEST 2009


I have submitted this as a bug
(http://biostat.mc.vanderbilt.edu/trac/Hmisc/ticket/29) but I am
wondering if anyone else has seen it or perhaps developed a
workaround.  I could certainly fix the LaTeX by hand, but I am using
this inside Sweave, so it is a bit cumbersome.  The exact same code
used to work fine, but something changed underneath it.  Even so,
perhaps I am using the latex() command incorrectly.

When I do a latex table with rownames but without cgroup, everything
is fine, but when I use cgroup (as in the second case), the rownames
column gets the first column's name and subsequent column names are
shifted. This worked fine for me a year ago, so something has changed
in my setup or in Hmisc. I have another machine with Hmisc_3.4-3
installed, and its cgroup()-ed table was correct as well.  I included
the output from sessionInfo() at the bottom.

test.df <- data.frame(row.names=letters[1:4], col1=1:4, col2=4:1, col3=4:7)

latex(test.df, file="", table.env=FALSE, center="none")

% latex.default(test.df, file = "", table.env = FALSE, center = "none") %
\begin{tabular}{lrrr}
\hline\hline
%% Comment added by ME -- this next line is the one that is fine without cgroup
\multicolumn{1}{l}{test.df}& \multicolumn{1}{c}{col1}&
\multicolumn{1}{c}{col2}& \multicolumn{1}{c}{col3} \tabularnewline
\hline a&$1$&$4$&$4$\tabularnewline
b&$2$&$3$&$5$\tabularnewline
c&$3$&$2$&$6$\tabularnewline
d&$4$&$1$&$7$\tabularnewline
\hline
\end{tabular}

latex(test.df, file="", n.cgroup=c(1,2), cgroup=c("","95\\% Conf. Limits"),
table.env=FALSE, center="none")

% latex.default(test.df, file = "", n.cgroup = c(1, 2), cgroup = c("",
"95\\% Conf. Limits"), table.env = FALSE, center = "none")
%
\begin{tabular}{lrcrr}
\hline\hline
\multicolumn{1}{l}{\bfseries test.df}& \multicolumn{1}{c}{\bfseries }&
\multicolumn{1}{c}{\bfseries }&
\multicolumn{2}{c}{\bfseries 95\% Conf. Limits} \tabularnewline
 \cline{4-5}
%% Comment added by ME -- this next line is the one that is broken with cgroup
\multicolumn{1}{l}{col1}& \multicolumn{1}{c}{}&
\multicolumn{1}{c}{col2}& \multicolumn{1}{c}{col3}&
\multicolumn{1}{c}{col1} \tabularnewline
\hline
a&$1$&&$4$&$4$\tabularnewline
b&$2$&&$3$&$5$\tabularnewline c&$3$&&$2$&$6$\tabularnewline
d&$4$&&$1$&$7$\tabularnewline
\hline \end{tabular}

I am attaching a .pdf of the two tables.  (I hope it goes through.)

sessionInfo()

R version 2.8.1 (2008-12-22) i486-pc-linux-gnu

locale: LC_CTYPE=en_US;LC_NUMERIC=C;LC_TIME=en_US;LC_COLLATE=en_US;LC_MONETARY=C;LC_MESSAGES=en_US;LC_PAPER=en_US;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US;LC_IDENTIFICATION=C

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] Hmisc_3.5-2

loaded via a namespace (and not attached): [1] cluster_1.11.13
grid_2.9.0 lattice_0.17-22 tcltk_2.9.0 [5] tools_2.9.0

I hope this is enough information to make the problem clear and that I
haven't missed something obvious.  Finally, I will subscribe to the
help list (I usually just search the archives), but I would appreciate
replies sent directly to me as well!

Thanks!

Michael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: x.pdf
Type: application/pdf
Size: 13471 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090423/6947664e/attachment-0002.pdf>


More information about the R-help mailing list