[R] Long command in Sweave

Gavin Simpson gavin.simpson at ucl.ac.uk
Fri Apr 13 18:17:16 CEST 2012


I use Emacs and ESS, with the coding standards in one of the R manuals.
I have to insert the carriage returns where I want them, but Emacs/ESS
indents the code correctly

G

On Fri, 2012-04-13 at 22:17 +0800, Wincent wrote:
> Thanks, Gavin and Duncan.
> 
> In that case, what I need is a suitable editor which can break the
> command properly.
> 
> All the best
> 
> On 13 April 2012 19:33, Gavin Simpson <gavin.simpson at ucl.ac.uk> wrote:
> > On Fri, 2012-04-13 at 17:46 +0800, Wincent wrote:
> >> Dear useRs,
> >>
> >> I am writing a vignette for a package, which contains long command like this,
> >> >reduce(Lipset_cs,"SURVIVAL",c("GNPCAP", "URBANIZA", "LITERACY", "INDLAB", "GOVSTAB"),explain="positive",remainder="exclude",case="CASEID")
> >> It is longer than the width a page and part of it will become "missing".
> >> Currently, I have to manually break the command into multiple lines.
> >> Is there a better way to handle such issue?
> >
> > Not that I am aware of.
> >
> >> It seems that others have raised similar question which seems to
> >> remain unsolved in a satisfactory fashion.
> >>
> >> Thanks for your kind attention in advance.
> >>
> >
> > 1) use some spacing and format the code over multiple lines
> >
> > reduce(Lipset_cs, "SURVIVAL",
> >       c("GNPCAP", "URBANIZA", "LITERACY", "INDLAB", "GOVSTAB"),
> >       explain="positive", remainder="exclude", case="CASEID")
> >
> > Isn't that more readable?! Any good R-aware editor should be able to
> > handle appropriate formatting of the code. I *never* write long lines in
> > my editor; I always break the code down to fit roughly into a 72 column
> > editor window.
> >
> > 2) if you want to force Sweave to respect your new formatting, use
> > argument `keep.source=TRUE` for the code chunk. Or set it document wide
> > using \SweaveOpts{option1=value1, option2=value2} etc in the preamble
> > (where optionX is one of the arguments and valueX what you want to set
> > that argument too.
> >
> > Thought IIRC, `keep.source=TRUE` is the default now and as such Sweave
> > will respect your formatting by default now - before it broke lines
> > where it could.
> >
> > In short get out of the habit of writing long lines of R code; you'll be
> > better in the long run laying your code out logically.
> >
> > HTH
> >
> > G
> >
> > --
> > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
> >  Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
> >  ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
> >  Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
> >  Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
> >  UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
> > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
> >
> >
> >
> 
> 
> 

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list