[R] commenting out a block of R code

Joshua Wiley jwiley.psych at gmail.com
Mon May 7 04:41:01 CEST 2012


Hi Ranjan,

To me, this is really a text editors job.  Feature-rich editors make
it trivial, for example in Emacs, you can select a region (whatever
size you want) and M-x comment-region automatically comments every
line in that region.  Similarly M-x uncomment-region will uncomment
every line.  If you were doing this all the time, you could bind some
keyseries to do it for you.  Vim has something similar, though I
forget the exact command.

A hack is:

if (FALSE) {
all the lines
you want
to be `commented'
}

which will leave them unevaluated at least.  Both of these have been
suggested before on the list, which is probably why Brian Ripley
suggested searching the archives.

Cheers,

Josh


On Sun, May 6, 2012 at 7:31 PM, Ranjan Maitra <maitra at iastate.edu> wrote:
> Dear friends,
>
> Is there an easy way of commenting out a block of R code after it has
> been written? (I am aware that R-aware editors can insert #
> line-by-line while it is being written, but I want to basically block
> out chunks of R code in a few strokes.)
>
> This question was asked on this mailing list some time ago: Professor
> Ripley's answer was to try the following:
>
> RSiteSearch(string="comment multiple lines")
>
> Perfectly fine, but inexplicably, I got searches back (seven
> pages) which do not seem to have any connection with what I am looking
> for.
>
> Is there an easy way of doing this?
>
> Many thanks and best wishes,
> Ranjan
>
> ______________________________________________
> R-help at 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.



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/



More information about the R-help mailing list