Skip to content

How can I comment out whole chunks of code?

5 messages · Mark, Duncan Murdoch, Gabor Grothendieck +2 more

#
Hello,

I know this has been discussed, but I haven't found an answer in the 
archives. Basically, I'd like to be able to comment out chunks of code 
(which may or may not be syntactically correct) without having to put 
the # symbol in front of each line (and, if possible, without having to 
adopt a new text editor).

My current R setup (XP) is very simple. I always have three windows 
open: the R console, my working directory, and a Notepad window 
containing my program. Adopting Tinn-R would probably solve this 
problem, but for simplicity I'd rather not move beyond Notepad (if 
possible).

Thanks for any help you can provide,

Mark
#
On 24/09/2008 4:03 PM, Mark Na wrote:
I think there is no solution that lives within your constraints.

If you keep syntactic correctness, you can wrap blocks in

if (FALSE) {
  ...
}

If you switch to a real editor, adding the # prefix to each line would 
not be a problem.

Duncan Murdoch
#
Also if there are no single quotes in your line you can surround them
with single quotes. Ditto for double quotes.

junk <- "
some R code possibly with
syntax errors
"

If the code is in a function you can omit the junk<-
part.
On Wed, Sep 24, 2008 at 4:10 PM, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
#
I know you don't want to adopt a new text editor but Tinn-R can 'comment' a block of code (inserting # in front of the selected lines.

Kevin
---- Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
#
just a thought: you might want to have a look at the brew package (R- 
forge). Instead of source()ing the document in the R console, you'd  
use brew(). By default, any text is considered a comment, only lines  
contained between <% %> will be run as R code.


baptiste
On 24 Sep 2008, at 21:03, Mark Na wrote: