Hi everybody, I use for the moment "#" at the begining of each line for comments. Is there any possibility to comment more than one line, like something which shows the beggingng and the end of the comment? Or is there a possibility to comment only a part of a line? Thanks, Mihai [[alternative HTML version deleted]]
A hash (#) anywhere on a line will comment out the rest of the line. Try! I don't think there is anything in R that will indicate the beginning and end of a "comment section" (like /* .... */ would in SAS). However most editors (and certainly emacs and Tinn-R) will allow you to comment out several lines. S?ren ________________________________ Fra: r-help-bounces at r-project.org p? vegne af Mihai.Mirauta at bafin.de Sendt: on 11-02-2009 09:32 Til: r-help at r-project.org Emne: [R] How to comment in R Hi everybody, I use for the moment "#" at the begining of each line for comments. Is there any possibility to comment more than one line, like something which shows the beggingng and the end of the comment? Or is there a possibility to comment only a part of a line? Thanks, Mihai [[alternative HTML version deleted]] ______________________________________________ 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.
Hi Mihai, one (very bad style) way would be if (FALSE) { comment comment comment } But putting a # in front of every line is easier to spot in the code. HTH, Stephan Mihai.Mirauta at bafin.de schrieb:> Hi everybody, > > I use for the moment "#" at the begining of each line for comments. > > Is there any possibility to comment more than one line, like something which shows the beggingng and the end of the comment? Or is there a possibility to comment only a part of a line? > > Thanks, > > Mihai > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >
> Hi Mihai, > > one (very bad style) way would be > > if (FALSE) { > comment > comment > comment > } >this works only if the enclosed text is syntactically valid r code. that is, you can't have multiline free text comments done this way, neither can you temporarily comment out unfinished and unparsable code. an extension to the parser that would accept multiline start-end comment tags, be it c-style /* */, perl-style =pod =cut, whatever, should be fairly trivial to implement. (the perl-style pod markup is particularly easy to parse, because it suffices to recognize '^=' on a line, no advanced pattern-matching needed.) somewhat surprising there is no such functionality there in r (or is there any?), it would be quite convenient. vQ
2009/2/11 <Mihai.Mirauta at bafin.de>:> > Hi everybody, > > I use for the moment "#" at the begining of each line for comments. > > Is there any possibility to comment more than one line, like something which shows the beggingng and the end of the comment? Or is there a possibility to comment only a part of a line? >Searching the mailing list archives for 'block comment' provides another hairy solution from Philippe Grosjean, which involves redefining '!' for character arguments: http://tolstoy.newcastle.edu.au/R/e2/help/06/10/2168.html I don't know if R-core would consider putting block comments (maybe with /* */ syntax) into R. There are problems with block comments since they have very non-local effects - once you've scrolled down a bit, how can you tell if code is commented or not? And modern editors are capable of commenting out large blocks with the '#' character, so maybe there's no demand. Python doesn't have them (which is my benchmark for language qualities at the moment): http://www.velocityreviews.com/forums/t355236-why-no-block-comments-in-python.html On reflection, block comments in R gets a -1 from me. Barry
I think you need to revisit the suggestion of how to use Tinn-R to ensure you are doing it properly. If its R code then if(FALSE) has already been mentioned as an alternative and another possibility is just enclose it in double quotes (or if there are double quotes in the passage then in single quotes): f <- function(x) { " here are some comments of mine" x+1 } On Wed, Feb 11, 2009 at 3:32 AM, <Mihai.Mirauta at bafin.de> wrote:> > Hi everybody, > > I use for the moment "#" at the begining of each line for comments. > > Is there any possibility to comment more than one line, like something which shows the beggingng and the end of the comment? Or is there a possibility to comment only a part of a line? > > Thanks, > > Mihai > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >