[R] How to comment in R

Greg Snow Greg.Snow at imail.org
Wed Feb 11 19:52:44 CET 2009


Stavros,

Thanks for the clarification and going further back in the credit for /* */.  

I don't think that the regex argument is a complete red herring (possibly a pink herring or burnt umber herring?).  The post I was responding to said that implementing it would be trivial, I think that the fact that Friedl spends 10 pages discussing it shows that it is less than trivial.  While the parser can process the comments without using regular expressions, some of the issues that Friedl brings up still need to be considered in deciding the rules.  Implementing this in the parser may well be trivial once the rules are decided on (but way beyond me), but I still think that deciding on the rules and documenting them is far from trivial.  

I remember having some C code that compiled fine and did as intended with one compiler, then when I tried compiling with a different compiler it threw an error based on the commenting (probably the difference was in the preprocessors, not the compilers), so the 2 different versions of the C compiler/preprocessor did not even agree on the rules (I don't remember emacs complaining either way).

Others have mentioned using sed as another way to add/strip comment markers to regions of code.  Along these lines someone could always use C-style (or PL/I style to be more correct but less common in my experience) comments, then run the code through a C preprocessor before submitting to R (then you just have to live with the rules of the preprocessor).

I have no problem with someone adding this capability to R, I just prefer that R-Core spends their time on higher priority items.  If someone else wants to contribute the change, I won't complain (unless it breaks my existing code, which is unlikely if done properly), I just wanted anyone who was thinking of doing this to think about some of the potential pitfalls so that if they implement it, they implement it well.


-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: macrakis at gmail.com [mailto:macrakis at gmail.com] On Behalf Of
> Stavros Macrakis
> Sent: Wednesday, February 11, 2009 11:22 AM
> To: Greg Snow
> Cc: Waclaw.Marcin.Kusnierczyk at idi.ntnu.no; Stephan Kolassa;
> mihai.mirauta at bafin.de; r-help at r-project.org
> Subject: Re: [R] How to comment in R
> 
> On Wed, Feb 11, 2009 at 12:32 PM, Greg Snow <Greg.Snow at imail.org>
> wrote:
> > ...The c-style of /* */ allows both types and you can comment out
> part of a line, but it is not simple to match and has its own
> restrictions.  Friedl in his regular expressions book takes 10 pages to
> develop a pattern to match these (and the final pattern is almost 2
> full lines of text in the book).  And this is without allowing
> nesting....
> 
> Though there is a real debate about the value of multiline, possibly
> nested, comments, the regular expression argument is a red herring.
> Lexical analysis of multiline comments is a solved problem (and not a
> particularly difficult one!), and matters only to language and editor
> implementors.  Emacs handles them with no problem.
> 
>            -s
> 
> PS And to give credit where credit is due (important on this mailing
> list), the /* */ syntax was defined by PL/I; C simply implemented an
> existing convention and popularized it. :-)




More information about the R-help mailing list