[R] Long command in Sweave
Gavin Simpson
gavin.simpson at ucl.ac.uk
Fri Apr 13 13:33:18 CEST 2012
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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
More information about the R-help
mailing list