[R] Sweave output from print.summary.glm is too wide

Duncan Mackay mackay at northnet.com.au
Wed Aug 19 04:14:24 CEST 2009


Oops

I forgot to mention ?xtable and ?latex in Frank Harrell's Hmisc or Design 
packages (I cannot remember)

Duncan

Hi Peter

If all else fails you can make the space between the columns smaller by 
changing the column spacing in latex
by:

\setlength\tabcolsep{3pt}

The default is 7pt. You may have to go a little higher if it looks cramped. 
I have gone down as far as 2pt using a small font size

Also changing the fontsize for the chunk can work wonders eg for small
\begin{small}
<< >>==
R code
@
\end{small}



HTH

Duncan Mackay
Department of Agronomy and Soil Science
Univeristy of New England
ARMIDALE NSW 2351
Email: home : mackay at northnet.com.au


At 10:10 19/08/2009, you wrote:
>Hi all
>
>I am preparing a document using Sweave; a really useful tool.  But I am 
>having a problem.
>
>Consider this toy example Sweave file:
>
>
>\documentclass{article}
>
>\begin{document}
><<echo=TRUE,results=verbatim>>=
>options(width=40)   # Set width to 40 characters
>hide <- capture.output(example(glm)) # Create an example of the problem, 
>but hide the output
>summary(glm.D93)   # This is where the problem is evident
>@
>\end{document}
>
>The intent of the  options(width=40)  command is to ensure the output does 
>not extend to far to the right of the page, as per the Sweave manual 
>Section A.14.  And in most cases, this does the job.
>
>Now, I run Sweave on the above file, run pdflatex.  Feel free to run the 
>above code to see the actual result, but here is an edited text version of 
>the output:
>
> > options(width = 40)
> > hide <- capture.output(example(glm))
> > summary(glm.D93)
>Call:
>glm(formula = counts ~ outcome + treatment, family = poisson())
>Deviance Residuals:
>1 2 3 4
>-0.67125 0.96272 -0.16965 -0.21999
>5 6 7 8
>-0.95552 1.04939 0.84715 -0.09167
>9
>-0.96656
>Coefficients:
>Estimate Std. Error
>(Intercept) 3.045e+00 1.709e-01
>outcome2 -4.543e-01 2.022e-01
>outcome3 -2.930e-01 1.927e-01
>treatment2 8.717e-16 2.000e-01
>treatment3 4.557e-16 2.000e-01
>z value Pr(>|z|)
>(Intercept) 17.815 <2e-16 ***
>outcome2 -2.247 0.0246 *
>outcome3 -1.520 0.1285
>treatment2 4.36e-15 1.0000
>treatment3 2.28e-15 1.0000
>
>
>The final pdf output file is mostly fine: but not all of the output 
>of  print.summary.glm  obeys the   width=40  command.
>
>The middle parts of the output are suitable wrapped (the coefficients, std 
>error, z and P-value bit), but the bits at the end (not shown) and the 
>start are not; for example, look at the  Call:  section of the output above.
>
>I'd be expecting the initial part of the output to appear something like 
>this, suitably wrapped:
>
>
> > summary(glm.D93)
>Call:
>glm(formula = counts ~ outcome +
>     treatment, family = poisson())
>
>
>As far as I can recall,  print.summary.glm  and  print.summary.lm  are the 
>only times I have seen this behaviour.  I found a similar thread posted 
>June 2009 ("overshoot of formula line in summary output of Sweave"); there 
>appeared no resolution in that thread, or after contacting the originator 
>of the post.
>
>So my question:
>* What can I do to ensure my output is not extending too far to the right 
>with  print.summary.glm?
>
>
>Thanks as always.
>
>P.
>
>
> > sessionInfo()
>R version 2.9.0 (2009-04-17)
>i486-pc-linux-gnu
>
>locale:
>LC_CTYPE=en_AU.UTF-8;LC_NUMERIC=C;LC_TIME=en_AU.UTF-8;LC_COLLATE=en_AU.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_AU.UTF-8;LC_PAPER=en_AU.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_AU.UTF-8;LC_IDENTIFICATION=C
>
>attached base packages:
>[1] stats     graphics  grDevices utils     datasets  methods   base
>
>other attached packages:
>[1] GLMsData_0.7
>
>loaded via a namespace (and not attached):
>[1] tools_2.9.0
> >
>
>
>
>
>
>
>
>Peter Dunn: Biostatistician
>School of Health and Sport Science
>Faculty of Science, Health and Education  ML-34
>University of the Sunshine Coast, Locked Bag 4
>Maroochydore DC Qld 4558
>
>Tel: +61 7 5456 5085
>Fax: +61 7 5430 2896
>Email: pdunn2 at usc.edu.au
>www.usc.edu.au ( http://www.usc.edu.au/ )
>
>CRICOS Provider Number: 01595D
>
>This communication is intended for the recipient only and should not be 
>forwarded, distributed or otherwise read by others without express 
>permission. The views expressed in this email are not necessarily those of 
>the University of the Sunshine Coast.
>
>--
>This message has been scanned for viruses and\ dangerous...{{dropped:8}}
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list