[R] [FORGED] Re: Block comment?

Duncan Murdoch murdoch.duncan at gmail.com
Sun Sep 3 02:29:14 CEST 2017

On 02/09/2017 6:57 PM, Rolf Turner wrote:
> On 03/09/17 03:56, William Dunlap via R-help wrote:
>> Is the reason you want a block comment containing code (as opposed to
>> arbitrary text) that you want to be able to easily run the commented out
>> code?  If so the 'if()' construct has the advantage that you only need to
>> change code at the start of the comment, not at both ends.
>> The if(FALSE) could be if(isTRUE(getOption("DEBUG_ISSUE_XYZ"))) so you
>> would not even have to change code to re-enable the debugging code, just
>> call options(DEBUG_ISSUE_XYX=TRUE)).
> (a) The foregoing is getting too subtle for my feeble brain.
> (b) A fundamental problem with the
>      if(FALSE) {
>         ...
>      }
> paradigm is that the enclosed code must be syntactically valid, and
> there are certainly situations in which one might wish to comment out
> sections of code that are *not* syntactically valid.  E.g. one might
> wish to comment out *part* of a piece of syntactically valid code for
> the purpose of experimenting with an alternative approach.

If the code is not syntactically valid, why would you expect the block 
comment to be syntactically valid?  The proposal at the start of this 
thread was that #{ would open the block and would be matched by }# to 
close the block.  What if the closing sequence occurred within the block 
unintentionally?  Then the poor feeble programmer would be even more 

I like the current rule:  any line starting with # is a comment. 
(Actually the rule is a bit more subtle than that, but it's close.)
If I want to comment out a block, I can spend a long time typing # at 
the start of every line, or I can ask my editor to do it.  I don't need 
to worry if something in the block unintentionally closes it, because 
that's impossible.  If the first line is a comment, all the rest are too.

Duncan Murdoch

More information about the R-help mailing list