Is it possible to have multi-line comments in R?

I found this old thread (over a year ago) that explains why R doesn't support multi-line comments (e.g. / * comment * / PHP).

I am wondering if this was allowed last year, or are there any other alternatives? (For example, in notepad ++ with npptor, you can mark a bunch of lines and press ctrl + q to mark them as comments, are there similar solutions for another IDE?)

+59
comments r
Nov 09 '10 at 7:25
source share
7 answers

You can, if you want, use stand-alone lines for multi-line comments—— I always thought it was prettier than if (FALSE) { } . The string will be evaluated and then discarded, since until the last line in the function nothing will happen.

 "This function takes a value x, and does things and returns things that take several lines to explain" doEverythingOften <- function(x) { # Non! Comment it out! We'll just do it once for now. "if (x %in% 1:9) { doTenEverythings() }" doEverythingOnce() ... return(list( everythingDone = TRUE, howOftenDone = 1 )) } 

The main limitation is that when you comment on a material, you have to look at your quotation marks: if you have one view inside, you will have to use another view for comment; and if you have something like "lines with" post-lines "inside this block, then there is no way for this method to be a good idea. But then there is still an if (FALSE) block.

Another limitation that both methods have is that you can only use such blocks only in places where the expression is syntactically correct - without commenting on parts of the lists, say.

Regarding what the IDE does: I'm a Vim user, and I find NERD Commenter a great tool for quickly commenting or decoding multiple lines. Very comfortable, very well documented.

Finally, the R prompt (at least under Linux) has a nice Alt - Shift - # to comment on the current line. It is very nice to put the line “on hold” if you are working with one liner, and then you understand that you need to prepare the step first.

+33
Nov 09 '10 at 19:47
source share

R Studio (and Eclipse + StatET): select the text and use CTRL + SHIFT + C to comment out a few lines in Windows. Or, command + SHIFT + C in OS-X.

+69
Feb 17
source share

CTRL + SHIFT + C in Eclipse + StatET and Rstudio.

+16
Nov 09 '10 at 8:07
source share

There are no multi-line comments in R on version 2.12 and are unlikely to change. In most environments, you can comment on blocks by highlighting and switching comments. In emacs, this is "Mx;".

+9
Nov 09 '10 at 7:30
source share
 if(FALSE) { ... } 

excludes multiple lines. However, these lines should still be syntactically correct, i.e. Cannot be comments in the right sense. However, useful for some cases.

+7
Nov 09 '10 at 13:04 on
source share

Unfortunately, there is still no multi-line comment in R.

If your text editor supports column mode, use it to add an empty line from #. If you use UltraEdit, Alt + c will put you in column mode.

+3
Nov 09 2018-10-11
source share

Add the following to your ~/.Rprofile file:

 exclude <- function(blah) { "excluded block" } 

Now you can exclude blocks as shown below:

 stuffiwant exclude({ stuffidontwant morestuffidontwant }) 
+1
Oct 26
source share



All Articles