[R] overshoot of formula line in summary output of Sweave
Ben Bolker
bolker at ufl.edu
Fri Jun 19 09:46:13 CEST 2009
Ken Knoblauch wrote:
>
> Ben Bolker <bolker <at> ufl.edu> writes:
>> > In the Sweave output for summary for several types
>> > of model objects and also for the comparison of models
>> > with anova, I find that that the display of the call(s)
>> > or formula does not obey the width option, even with
>> > keep.source=TRUE set, so that a long formula will overshoot
>> > the margins in the document. I would like to know if
>> > there is a good way to correct that. Looking at the
>> > print.summary methods for lm, glm and several others,
>> > I see that a construct like deparse(obj$call) is used
>> > to generate the text. The deparse function takes a
>> > "width.cutoff" argument, that could be used in these cases,
>> > if it were possible to pass a value to it, or if its default
>> > value could be set with an option. Other methods do not
>> > use deparse, (print.summary.polr in MASS uses dput and
>> > anovalist.nls also does it differently) so such a solution
>> > would not work universally without altering these functions.
>> >
>> > Here is a toy example that illustrates the overshoot of the formula
>> >
>> > \documentclass[12pt]{article}
>> > \usepackage{geometry}
>> > \geometry{left=2in,right=2in}
>> > \begin{document}
>> > <<keep.source=TRUE>>=
>> > op <- options(width = 65, digits = 3)
>> > ddataframe <- data.frame(AAAAA = 1:10,
>> > BBBBB = factor(letters[1:2]),
>> > CCCCC = factor(LETTERS[1:5]),
>> > SSSSS = factor(paste("S", 1:10, sep = "")),
>> > RRRRR = rnorm(10))
>> >
>> > mod1 <- lm(RRRRR ~ AAAAA + BBBBB + CCCCC + SSSSS,
>> > ddataframe)
>> > summary(mod1)
>> > @
>> > \end{document}
>>
>> A quick guess: try keep.source=TRUE and format your commands
>> as you would like to see them appear ...
>>
>> Ben Bolker
> Thanks, Ben, for the response.
>
> As you can see, in the example above, I did use keep.source=TRUE.
> I can always format it by hand in the final document, but I was
> looking for an automatic formating solution, if it was something
> obvious or not that I have missed.
> It seems to me that the problem is in print.summary and anova
> methods. For lm and glm, they use deparse(obj$call).
> deparse takes a width.cutoff argument, which is set
> by default to 60L, but you can't access it directly from the
> summary or anova arguments. It's a bit heavy-handed, but
> a solution is to change the default value of width.cutoff in
> base, using assignInNamespace. Making my own deparse
> in the workspace doesn't work because the base functions
> don't see it. Other methods don't necessarily use deparse.
> I've seen a few that use dput(), which doesn't have a width
> argument, so I'm losing hope of finding a general, automatic
> solution. Thanks, in any case.
>
> Ken
>
Yes, sorry -- I realized after I replied that I had read your question
too quickly.
I wonder if there is a LaTeX-side solution, i.e. constructing a
verbatim-like environment that breaks lines?
Ben
--
View this message in context: http://www.nabble.com/overshoot-of-formula-line-in-summary-output-of-Sweave-tp24053269p24106935.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list