[R] Is there a construct for conditional comment?

David Winsemius dwinsemius at comcast.net
Thu Aug 20 19:27:36 CEST 2009


On Aug 20, 2009, at 1:19 PM, Duncan Murdoch wrote:

> On 8/20/2009 11:54 AM, Steve Jaffe wrote:
>> Why not
>> if ( 0 ) {
>> commented with zero
>> } else {
>> commented with one
>> }

But an extremely simple modification "succeeds":

  if ( 0 ) {"
  commented with zero
  "} else {"
  commented with one
  "}

Returns:
[1] "\ncommented with one\n"


If bothered by the \n's then the ""'s could be on the same line as the  
comment

-- 
David Winsemius
>
>
> Because that doesn't work unless the comments are syntactically  
> correct R.  For example, yours gives:
>
> Error in source("clipboard") : clipboard:2:11: unexpected symbol
> 1: if ( 0 ) {
> 2: commented with
>             ^
>
> In C++, you can put nearly arbitrary junk in the #if 0 block, and it  
> will be stripped by the preprocessor.
>
> Duncan Murdoch
>
>> Greg Snow-2 wrote:
>>> I believe that #if lines for C++ programs is handled by the  
>>> preprocessor,
>>> not the compiler.  So if you want the same functionality for R  
>>> programs,
>>> it would make sense to just preprocess the R file.
>>>> In C++, I can use the following construct to choice either of the  
>>>> two
>>>> blocks the comment but not both. Depending on whether the number  
>>>> after
>>>> "#if" is zero or not, the commented block can be chose. I'm  
>>>> wondering
>>>> if such thing is possible in R?
>>>> #if 0
>>>> commented with 0
>>>> #else
>>>> commented with 1
>>>> #endif
>>>> Regards,
>>>> Peng
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list