Thanks Andrew, I didn't know about the keep.source option!

Still this is also only a workaround. If I now change the margins of the
document, I have to manually fix the linebreaks in the correct places to
make sure that the space is correctly used. Besides, the automatic
pretty-printing is a nice feature that gets disabled by keep.source=TRUE, so
I now have to do it by hand.

In an ideal world, Sweave would automatically insert linebreaks in the
correct spots to respect the \textwidth setting, without even needing to set
a width option, much in the way that the listings package prints code. But
it seems this cannot be done at the moment, so the workarounds will have to
do. Your workaround is much better than mine, though!

Cheers,
Enrico

On Mon, May 26, 2008 at 3:22 PM, Andrew Robinson <
A.Robinson@ms.unimelb.edu.au> wrote:

> Enrico,
>
> try
>
> <<test, keep.source=TRUE>>=
>
> that should keep your linebreaks.
>
> Cheers
>
> Andrew
>
>
> On Mon, May 26, 2008 at 03:15:39PM -0400, Enrico Rossi wrote:
> > Hello,
> >
> > I'm learning to use Sweave, and I've run into a problem: sometimes, when
> > entering long lines of input and using long variable names, Sweave will
> not
> > insert linebreaks in a way that respects the width setting. This causes
> > undesirable overflows into the margins in the latex file. For example,
> > consider the following document (adapted from the GLM example):
> >
> > \documentclass{article}
> > \begin{document}
> >
> > <<setup,include=FALSE,echo=FALSE>>=
> > options(width=80)
> > @
> >
> > <<test>>=
> > countsasdfasdfasdf <- c(18,17,15,20,10,20,25,13,12)
> > outcomeasdfasdfasdf <- gl(3,1,9)
> > treatmentasdfasdfasdfasdf <- gl(3,3)
> > glm.D93 <- glm(countsasdfasdfasdf ~ outcomeasdfasdfasdf +
> > treatmentasdfasdfasdfasdf, family=poisson())
> > @
> >
> > \end{document}
> >
> > When I compile this, treatmentasdfasdfasdfasdf sticks out into the right
> > margin. The linebreak is inserted after the last comma, so that the line
> as
> > printed is 85 characters long, even though I set width to 80 at the top.
> > Ideally, Sweave would set the linebreak after the last plus symbol.
> >
> > There is a simple workaround that I have been using: if a line causes
> > problems, set width to something smaller before the line, and set it back
> > afterwards. It's pretty clumsy though, and I wonder if there is a better
> > way. My understanding is that there is no way to manually set linebreaks,
> > what a pity!
> >
> > I am using R 2.6.2 and the MacTex 2007 distribution. If this problem has
> > been fixed in a recent version, I apologize.
> >
> > Cheers,
> > Enrico
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help@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.
>
> --
> Andrew Robinson
> Department of Mathematics and Statistics            Tel: +61-3-8344-6410
> University of Melbourne, VIC 3010 Australia         Fax: +61-3-8344-4599
> http://www.ms.unimelb.edu.au/~andrewpr<http://www.ms.unimelb.edu.au/%7Eandrewpr>
> http://blogs.mbs.edu/fishing-in-the-bay/
>

	[[alternative HTML version deleted]]

