[R] [Fwd: Re: Block comments in R?]

2006-10-05 Thread Philippe Grosjean
Ooops! Sorry, I send it only to Uwe Ligges the first time.
Best,

Philippe Grosjean

This is perhaps another solution, more elegant in the way the block
comment is written... but it requires to redefine `!` and slows it a
little bit because it tests first its arguments before calling
.Primitive(!):

It takes advantage of `!` being not defined for character arguments:

 !2
[1] FALSE
 !some text
Error in !some text : invalid argument type

So, now, we will define it for character arguments (invisibly returns
the argument)

 `!`- function(x)
+   if (inherits(x, character) == FALSE)
+   .Primitive(!)(x) else invisible(x)


Now, `!` can be used to construct a block comment:

 A R script with block comments =

1+1 # This is a line comment

!'
This is a block comment spread
on several lines...
'

ls()

!!'
This is another block comment, possibly of higher
importance than the previous one
'
search()

!!!'
For color syntax highlighting and to better detect
the end of block comments, one may also decide to
use the same code for opening and closing the comments
like it is the present case
!!!'

!'
Note that the only constraint is to escape single quotes
in block comments (or not to use single quotes)
Of course, one could also decide to use double quotes
instead of single quotes
!'

!'
Now, it would be nice to have a little patch of .Primitive(!)
that simply displays no error message in case the argument of
`!`is a character sting. So, the hock would not be required
any more
!'

 And of the R script =

Best,

Philippe Grosjean


Uwe Ligges wrote:
 
 Robin Hankin wrote:
 On 5 Oct 2006, at 10:05, Uwe Ligges wrote:


 Wee-Jin Goh wrote:
 Hello list,

 Is there any way to perform a block comment in R? In C++, anything in
 between a /* and */ is considered a comment, and it allows
 programmers to comment out chunks of code for testing and debugging.
 Is there such a feature in R?

 This has frequently been asked on the list. Try to google for it. You
 will find answers like

 if(FALSE){
  code block
  commented
 }



 That method doesn't work for me:

 if(FALSE){

 if(12)
   print(12)
 else
   print(12)

 }
 
 
 Use an editor that comments out a whole block which is what I do all the 
 time, e.g. use Tinn-R, Emacs or WinEdt, to mention just a few of them.
 
 Or you can go ahead and use
 
 if(FALSE){
 
 if(12)
print(12)
 else
print(12)
 
 }
 
 
 or
 
 if(FALSE){'
 
 if(12)
print(12)
 else
print(12)
 
 '}
 
 
 Uwe
 
 
 returns an error.  How would I comment out that block of (incorrect) code?







 or use a good editor that supports commenting and uncommenting blocks.


 Uwe Ligges


 -- 
 Robin Hankin
 Uncertainty Analyst
 National Oceanography Centre, Southampton
 European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743




 
 __
 R-help@stat.math.ethz.ch 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.
 


__
R-help@stat.math.ethz.ch 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.


Re: [R] [Fwd: Re: Block comments in R?]

2006-10-05 Thread Barry Rowlingson
Philippe Grosjean wrote:

 
 It takes advantage of `!` being not defined for character arguments:
 

  *gasp*

  how much R code is destined to feature on www.thedailywtf.com in the 
future?

  whats the chances of block commenting being included in a future 
version? and more generally, is there a feature request system, or 
discussion of whats going in new releases? the nearest I can find is the 
'ideas' file:

http://developer.r-project.org/ideas.txt

  which has a bit of a 1990's feel to it (okay, it is in the 'Older 
Material' section).


Barry

__
R-help@stat.math.ethz.ch 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.


Re: [R] [Fwd: Re: Block comments in R?]

2006-10-05 Thread Duncan Murdoch
On 2006-10-5 9:20, Barry Rowlingson wrote:
 Philippe Grosjean wrote:
 
 
 It takes advantage of `!` being not defined for character arguments:
 
 
   *gasp*
 
   how much R code is destined to feature on www.thedailywtf.com in the 
 future?
 
   whats the chances of block commenting being included in a future 
 version? and more generally, is there a feature request system, or 
 discussion of whats going in new releases? the nearest I can find is the 
 'ideas' file:

There's a feature request system (one of the categories of bug report is 
  wishlist).

I think a specific proposal with some work behind it would probably get 
action in a case like this.  That is, block comments would be nice 
likely won't get acted on, but block comments in the form ... which is 
used by other language ..., which has the fantastic properties ... and 
no downside, and which could be implemented by the following patch to 
the parser,, likely would.

Duncan Murdoch


 
 http://developer.r-project.org/ideas.txt
 
   which has a bit of a 1990's feel to it (okay, it is in the 'Older 
 Material' section).
 
 
 Barry
 
 __
 R-help@stat.math.ethz.ch 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.

__
R-help@stat.math.ethz.ch 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.