R: Comment out block of code

user702432 picture user702432 · Feb 2, 2012 · Viewed 385.1k times · Source

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?

Answer

John picture John · Feb 2, 2012

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.