[R] How to comment out multiple lines in R source code?

Sven Garbade garbade at psy.uni-muenchen.de
Thu Oct 11 19:11:27 CEST 2001


Emmanuel Paradis wrote:
> 
> At 07:33 11/10/01 +0100, Prof Brian D Ripley <ripley at stats.ox.ac.uk> wrote:
> >On Wed, 10 Oct 2001, [iso-8859-1] Göran Broström wrote:
> >
> >> On 10 Oct 2001 rossini at blindglobe.net wrote:
> >>
> >> > >>>>> "jl" == jonathan li <jonathan_li at agilent.com> writes:
> >> >
> >> >     jl> Hi, Is there a way to comment out multiple lines at once in R
> >> >     jl> source code like C language's /* */ struct? This is quite
> >> >     jl> useful when one is testing different sections of a source
> >> >     jl> code.
> >> >
> >> > One alternative is to use editor macros for this.
> >> >
> >> > (X)Emacs, when using ESS, supports comment-region and uncomment-region
> >> > commands.
> >> >
> >> > best,
> >> > -tony
> >>
> >> You may also try
> >>
> >> if (FALSE){
> >> ...
> >> ...
> >> }
> >
> >Yes, you will see that in e.g. the MASS scripts to comment out S code that
> >does not (yet) work in R.
> >
> >One warning: in that method the `commented' code has to syntactically
> >valid, and that has caught me more than once.   So I usually use ESS's
> >methods.
> 
> In (X)Emacs, you can add a character at the beginning of several lines at
> once by selecting a block of lines, and then typing C-x r t # (where you
> can replace # by any other character or even a string; `C-x' means
> `Ctrl-x'). This does not need ESS. You can even add the # in the middle of
> the lines if your block selection starts at this point (in case you want to
> comment out the right hand-side of a command... maybe not very usual).
> 
> BTW, the possibility to (un)comment out a block a R commands does not
> appear in the ESS menu (it does in C-mode), and I did not find it in ESS's
> doc (but I admit I did not read it all carefully).

You can type M-x comment-region to comment and C-u M-x comment-region to
uncomment a region in (X)Emacs ESS-Mode.

Best, Sven
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list