R: Comment out block of code [duplicate]
Possible Duplicate:
R: Multiline Comment Workarounds?
I want to comment out several lines of code in R. Is there any way of doing it without having to put a # before each line - sort of like /* blocked out code */
in SAS?
Most of the editors take some kind of shortcut to comment out blocks of code. The default editors use something like command or control and single quote to comment out selected lines of code. In RStudio it's Command or Control+/. Check in your editor.
It's still commenting line by line, but they also uncomment selected lines as well. For the Mac RGUI it's command-option ' (I'm imagining windows is control option). For Rstudio it's just Command or Control + Shift + C again.
These shortcuts will likely change over time as editors get updated and different software becomes the most popular R editors. You'll have to look it up for whatever software you have.
A sort of block comment uses an if statement:
if(FALSE) {
all your code
}
It works, but I almost always use the block comment options of my editors (RStudio, Kate, Kwrite).
Wrap it in an unused function:
.f = function() {
## unwanted code here:
}