Quantcast

Long command in Sweave

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Long command in Sweave

Wincent
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?
It seems that others have raised similar question which seems to
remain unsolved in a satisfactory fashion.

Thanks for your kind attention in advance.

--
Wincent Ronggui HUANG
Sociology Department of Fudan University
PhD of City University of Hong Kong
http://homepage.fudan.edu.cn/rghuang/cv/

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Long command in Sweave

Duncan Murdoch-2
On 12-04-13 5:46 AM, 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?

No.

> It seems that others have raised similar question which seems to
> remain unsolved in a satisfactory fashion.

You can turn on auto-formatting, but it is a worse solution, because it
will lose all formatting from the original, including comments, white
space, etc.  Use Sweave option keep.source=FALSE to do this.

Duncan Murdoch

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Long command in Sweave

Gavin Simpson
In reply to this post by Wincent
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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Long command in Sweave

Wincent
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 <[hidden email]> 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
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>
>
>



--
Wincent Ronggui HUANG
Sociology Department of Fudan University
PhD of City University of Hong Kong
http://homepage.fudan.edu.cn/rghuang/cv/

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Long command in Sweave

Yihui Xie-2
You can probably try knitr; see the manual for example:
https://github.com/downloads/yihui/knitr/knitr-manual.pdf

Code reformatting is based on the formatR package
(https://github.com/yihui/formatR/wiki), which tries to preserve your
comments while breaking your long lines into shorter ones.

However, the absolutely reliable answer is that you should do it by
yourself (either manually or with a decent code editor).

Regards,
Yihui
--
Yihui Xie <[hidden email]>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA



On Fri, Apr 13, 2012 at 9:17 AM, Wincent <[hidden email]> 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 <[hidden email]> 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
>> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>>
>>
>>
>
>
>
> --
> Wincent Ronggui HUANG
> Sociology Department of Fudan University
> PhD of City University of Hong Kong
> http://homepage.fudan.edu.cn/rghuang/cv/
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Long command in Sweave

Gavin Simpson
In reply to this post by Wincent
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 <[hidden email]> 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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

______________________________________________
[hidden email] 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.
Loading...