[long:] Re: [R] problem with latex of object summary reverse
Frank E Harrell Jr <fharrell at virginia.edu> wrote:
Sorry to bother you again, I use the latex command with Sweave, and I would like to see the reports come out well without manual interventions on some tex files.
latex(object, file='') works with Sweave's <<results=tex>>= construct.
As in my previous note I could not duplicate that on Linux using the standard tetex distribution of latex etc. Please send output from the version command (I need to at least see the OS you are using) and your complete script (which you did not send before) so that I can run it exactly as you do, if you still cannot get it to work.
Thanks a lot for your help. I use the standard tetex distribution that comes with linux debian (sarge). I could also duplicate the problem on a another machine running debian woody. cunegonde:~> latex --version TeX (Web2C 7.3.7) 3.14159 kpathsea version 3.3.7 Copyright (C) 1999 D.E. Knuth. [... snip copyright info] Here is the transcript of a very short R session showing the latex problem with summary: ########################################################## R : Copyright 2003, The R Development Core Team Version 1.7.0 (2003-04-16) [snip the R intro text]
options(STERM='iESS', editor='emacsclient') library(Hmisc)
Hmisc library by Frank E Harrell Jr Type library(help='Hmisc'), ?Overview, or ?Hmisc.Overview') to see overall documentation. Hmisc redefines [.factor to drop unused levels of factor variables when subscripting. To prevent this behaviour, issue the command options(drop.unused.levels=F). Attaching package 'Hmisc': The following object(s) are masked from package:methods : show The following object(s) are masked from package:base : [.factor %in% interaction [.terms
set.seed(1)
y<-factor(sample(c('a','b','c'),100,T))
x<-runif(100)
a<-summary(y~x,method='reverse')
options(digits=3)
a
Descriptive Statistics by y +-+-----------------+-----------------+-----------------+ | |a |b |c | | |(N=27) |(N=38) |(N=35) | +-+-----------------+-----------------+-----------------+ |x|0.474/0.548/0.724|0.261/0.446/0.626|0.284/0.591/0.853| +-+-----------------+-----------------+-----------------+
latex(a)->la
This is TeX, Version 3.14159 (Web2C 7.3.7)
(/tmp/Rtmp973/file66334873.tex
LaTeX2e <2001/06/01>
Babel <v3.7h> and hyphenation patterns for american, french, german, ngerman, n
ohyphenation, loaded.
(/usr/share/texmf/tex/latex/base/report.cls
Document Class: report 2001/04/21 v1.4e Standard LaTeX document class
(/usr/share/texmf/tex/latex/base/size10.clo))
(/usr/share/texmf/tex/latex/misc/geometry.sty
(/usr/share/texmf/tex/latex/graphics/keyval.sty)
(/usr/share/texmf/tex/latex/config/geometry.cfg))
No file file66334873.aux.
Underfull \hbox (badness 10000) in paragraph at lines 20--21
[1] (./file66334873.aux)
LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.
)
(see the transcript file for additional information)
Output written on file66334873.dvi (1 page, 820 bytes).
Transcript written on file66334873.log.
###############################################################
And now, the faulty latex file (a.tex):
% latex.default(cstats, title = title, caption = caption, rowlabel = rowlabel, col.just = col.just, numeric.dollar = FALSE, insert.bottom = legend, rowname = lab, dcolumn = dcolumn, extracolheads = extracolheads, extracolsize = Nsize, ...)
%
\begin{table}[!tbp]
\begin{center}
\caption{Descriptive Statistics by y\label{a}}
\begin{tabular}{lccc}\hline\hline
\multicolumn{1}{l}{}&
\multicolumn{1}{c}{a}&
\multicolumn{1}{c}{b}&
\multicolumn{1}{c}{c}
\\ \multicolumn{1}{l}{{\scriptsize $N=27$}}&\multicolumn{1}{c}{{\scriptsize $N=38$}}&\multicolumn{1}{c}{{\scriptsize $N=35$}}\\ \hline
x&{\scriptsize 0.474~}{0.548 }{\scriptsize 0.724} &{\scriptsize 0.261~}{0.446 }{\scriptsize 0.626} &{\scriptsize 0.284~}{0.591 }{\scriptsize 0.853} \\
\hline
\end{tabular}
\end{center}
\noindent {\scriptsize $a$\ }{$b$\ }{\scriptsize $c$\ } represent the lower quartile $a$, the median $b$, and the upper quartile $c$\ for continuous variables.\\
\end{table}
###############################################################
The line which starts with:
\\ \multicolumn{l}{1}{{\scriptsize$N=27$}}&\multicolumn{1}{c}{[...]
should read:
\\ \multicolumn{l}{1}{}&\multicolumn{1}{c}{\scriptsize$N=27$}{[...]
I use your libraries and also Sweave a lot (Sweave is
actually the major reason why I decided recently to use R
rather than Stata: documenting the analysis is fun when you
can produce nice tables and graphs automatically in a LaTeX
document). Also, I find your libraries and documentation
truly amazing.
Thanks again,
Philippe Glaziou Epidemiologist Pasteur Institute of Cambodia