Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: Comment out block of code [duplicate]

Tags:

comments

r

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?

like image 432
user702432 Avatar asked Feb 02 '12 05:02

user702432


People also ask

How do I comment out a chunk of code in R?

If you use RStudio, you can use the keyboard shortcut Ctrl + Shift + C ( Command + Shift + C on macOS) to comment out a line of text.

How do I comment out multiple lines of code in R?

The easiest way to create a multi-line comment in RStudio is to highlight the text and press Ctrl + Shift + C. You can just as easily remove the comment by highlighting the text again and pressing Ctrl + Shift + C.

How do you comment out code quickly?

PDT allows you to quickly and easily comment and uncomment code by selecting a line or a block of text and tagging it as a comment. Comments can be added to single lines of code (Ctrl + /) or blocks of code (Ctrl + Shift + /).

Does R support multi-line comments?

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


1 Answers

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.

like image 141
John Avatar answered Sep 23 '22 08:09

John