Multiline Comment Workarounds?

HamiltonUlmer picture HamiltonUlmer · Aug 5, 2009 · Viewed 55.4k times · Source

I (sort of) already know the answer to this question. But I figured it is one that gets asked so frequently on the R Users list, that there should be one solid good answer. To the best of my knowledge there is no multiline comment functionality in R. So, does anyone have any good workarounds?

While quite a bit of work in R usually involves interactive sessions (which casts doubt on the need for multiline comments), there are times when I've had to send scripts to colleagues and classmates, much of which involves nontrivial blocks of code. And for people coming from other languages it is a fairly natural question.

In the past I've used quotes. Since strings support linebreaks, running an R script with

"
Here's my multiline comment.

"
a <- 10
rocknroll.lm <- lm(blah blah blah)
 ...

works fine. Does anyone have a better solution?

Answer

Salvador Dali picture Salvador Dali · Apr 14, 2013

You can do this easily in RStudio:

select the code and click CTR+SHIFT+C to comment/uncomment code.