Comment out region in R script in ESS mode in (X)Emacs

One of the major problem in R is that there is no way to comment out a block of code using a block comment such as /* */ in C. This makes it very difficult to test and debug code in R. One of the way out is to wrap the code that you want to comment out using if (FALSE) {} block. Unfortunately, the wrapped up code has to be syntactically correct for this thing to work, that means no code comments.

In ESS mode in (X)Emacs you can use M-x comment-region to comment out a selected block of code. You need to use C-u M-x comment-region to uncomment. You can also quickly add comment at the end of the line using line-end comment shortcut: M-;. Strangely, there is not good way to do this in R-specific editor such as RKWard in linux.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s