Patrick Drechsler
2004-Sep-26 12:24 UTC
[R] Sweave: superfluous newline (`\\') in tex file
Hi, I'm having trouble sweaving the following example: --8<------------------------schnipp------------------------->8--- \documentclass{article} \begin{document} \SweaveOpts{echo=FALSE} @ <<>>rm(list=c(ls())) library(Hmisc) library(ISwR) data(energy) energy$log <- log(energy$expend) attach(energy) @ %def @ <<results=tex>>mysum <- summary(stature ~ expend + log, method="reverse", test=T) latex(mysum, file='', caption="foo bar", label="tab:foobar" ) @ %def \end{document} --8<------------------------schnapp------------------------->8--- Here's the resulting tex file (sorry for the long lines): --8<------------------------schnipp------------------------->8--- \documentclass{article} \usepackage{/usr/local/lib/R/share/texmf/Sweave} \begin{document} % 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] \caption{foo bar\label{tab:foobar}} \begin{center} \begin{tabular}{lccc}\hline\hline \multicolumn{1}{l}{}& \multicolumn{1}{c}{lean}& \multicolumn{1}{c}{obese}& \multicolumn{1}{c}{Test Statistic} \\ &\multicolumn{1}{c}{{\scriptsize $N=13$}}&\multicolumn{1}{c}{{\scriptsize $N=9$}}&\\ \hline expend&{\scriptsize 7.48~}{ 7.90 }{\scriptsize 8.11} &{\scriptsize 9.21~}{ 9.69 }{\scriptsize 11.51} &$ F_{1,20}=17 ,~ P<0.001 $\\ log&{\scriptsize 2.012233~}{2.066863 }{\scriptsize 2.093098} &{\scriptsize 2.220290~}{2.271094 }{\scriptsize 2.443216} &$ F_{1,20}=17 ,~ P<0.001 $\\ \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.\\ \\ %% <- ERROR! Test used: Wilcoxon test \end{table} \end{document} --8<------------------------schnapp------------------------->8--- And here's the error message: ,---- | ERROR: LaTeX Error: There's no line here to end. | | --- TeX said --- | | See the LaTeX manual or LaTeX Companion for explanation. | Type H <return> for immediate help. | ... | | l.27 | | --- HELP --- | A \newline or \\ command appears between paragraphs, where it | makes no sense. If you're trying to ``leave a blank line'', use | a \vspace command. `---- Is there a way to suppress the extra newline `\\' without editing the Rnw file? I couldn't find anything in the archives describing this problem. TIA, Patrick Versions: Thorsten's noweb-mode (PRERELEASE). RCS: $Id: noweb-mode.el,v 1.14 2002/06/20 21:52:06 rsparapa Exp $ Emacs : GNU Emacs 21.3.50.6 (i686-pc-linux-gnu, X toolkit, Xaw3d scroll bars) of 2004-09-07 on trurl Package: ess-mode 5.2.3 R : Copyright 2004, The R Foundation for Statistical Computing Version 1.9.1 alpha (2004-06-07), ISBN 3-900051-00-3 -- "I'm all in favor of keeping dangerous weapons out of the hands of fools. Let's start with typewriters." -- Frank Lloyd Wright (1868-1959)
Patrick Drechsler
2004-Sep-26 12:28 UTC
[R] Sweave: superfluous newline (`\\') in tex file
Patrick Drechsler wrote on 26 Sep 2004 13:24:31 MET:> Is there a way to suppress the extra newline `\\' without editing > the Rnw file?sorry, typo: s/Rnw/tex/ Patrick -- Black Holes result from God dividing the universe by zero.
Patrick Drechsler
2004-Sep-28 05:50 UTC
[Hmisc] proposal for change in latex.summary.formula.reverse (was: [R] Sweave: superfluous newline (`\\') in tex file)
Hi, well, it wasn't a Sweave problem after all. Seems to have something to do with the function `latex.summary.formula.reverse' in the package Hmisc. Following change seems to help (at least for my purpose): --8<------------------------schnipp------------------------->8--- *** /usr/local/lib/R/library/Hmisc/R/Hmisc 2004-09-28 07:37:26.000000000 +0200 --- /usr/local/lib/R/library/Hmisc/R/Hmisc.original 2004-09-28 07:38:28.000000000 +0200 *************** *** 16156,16162 **** 'Numbers after percents are frequencies.', sep="\n") if(length(testUsed)) ! legend <-paste(legend,'\n\n', if(length(testUsed)==1)'Test used:' else 'Tests used:', if(length(testUsed)==1) paste(testUsed,'test') else paste(paste('$^{',1:length(testUsed),'}$',testUsed, --- 16156,16162 ---- 'Numbers after percents are frequencies.', sep="\n") if(length(testUsed)) ! legend <-paste(legend,'\\\\\n','\n\n', if(length(testUsed)==1)'Test used:' else 'Tests used:', if(length(testUsed)==1) paste(testUsed,'test') else paste(paste('$^{',1:length(testUsed),'}$',testUsed, --8<------------------------schnapp------------------------->8--- But since my knowledge of R is rather small I have no idea if these has any other drawbacks. Any comments? How would I go about changing this for my setup only? Is renaming Hmisc to something like pdHmisc ok? Patrick -- Do you remember when you only had to pay for windows when *you* broke them?
Apparently Analagous Threads
- [Hmisc] latex() with ctable=T inserting unwanted empty line in .tex file when used on summary.formula(method="reverse") object
- problem with latex of object summary reverse
- Latex problem in Hmisc (3.8-1) and Mac Os X with R 2.11.1
- Package Hmisc, functions summary.formula() and latex(), options pdig, pctdig, eps and prmsd
- (kein Betreff)