[R] Multi-line comments?

Jonathan Baron baron at psych.upenn.edu
Wed Jul 22 17:15:40 CEST 2009


On 07/22/09 07:30, Mark Knecht wrote:
> Hi,
>    I looked in the language definition and was surprised. Is there
> really no multi-line/block comment defined in R?
> 
>    I wanted to comment out 20 lines that I'm moving to a function but
> didn't want to delete them. Is there no defined way to get around
> using a # on each of the 20 lines?

This topic has come up before and the answer seems to be no, although
you can do tricky things like defining a function containing the
comment as a quoted string (beginning and ending with quote marks), or
putting a quoted string after an if() for a condition that isn't met.
It helps that line breaks are allowed in quoted strings.

However

With (x)emacs and ESS, you can say
M-x comment-region
after defining a region with point and mark.

I got tired of typing this, so I defined the following in my
.xemacs/init.el and .emacs files:

(global-set-key "\M-r" 'comment-region)

So now I do it with "alt-R".  That key may have had some other
purpose, but not one I ever used.

I think the alt key is something else on a Mac.  And I have no idea
whether this will work on Windows.

Jon
-- 
Jonathan Baron, Professor of Psychology, University of Pennsylvania
Home page: http://www.sas.upenn.edu/~baron




More information about the R-help mailing list