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? Thanks, Mark
Try if (FALSE) { ... } On Wed, Jul 22, 2009 at 10:30 AM, Mark Knecht<markknecht at gmail.com> 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? > > Thanks, > Mark > > ______________________________________________ > 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. >
On Wed, Jul 22, 2009 at 4:30 PM, Mark Knecht<markknecht at gmail.com> wrote:> ? 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?Just like you, I have been longing for that myself. It seems that the answer is negative, so I have ended up using if (1==0) { # code goes here } although is not really nice to look at. -- Michael Knudsen micknudsen at gmail.com http://lifeofknudsen.blogspot.com/
On Wed, Jul 22, 2009 at 3:30 PM, Mark Knecht<markknecht at gmail.com> 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?Hmmm I think this might be a FAQ... Usual suggestions are: 1. use an editor that can do un/commenting of regions. 2. Stick it in an if(FALSE){ ... } block, but that's only good if it's syntactically correct. I prefer: 3. Manage your code under a decent SCM and don't fear the delete. Barry
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? > > Thanks, > Mark > > ______________________________________________ > 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. >Hi, This issue has come up before, and as far as I know there is no multiline comment. However, there are a few ways of commenting out larges pieces of code. - Use a good text editor, Kate (KDE) allows you to select the 20 lines and press Ctrl-D to comment them all at once. - Use a setup like: if(FALSE) { line1 ... line20 } And set FALSE to TRUE if you want to let the code be executed. These are probably not the only ones, but this is what I could think of right now. cheers and good luck, Paul -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul
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