That works if everything within the brackets is proper R code (though if(FALSE) reads better to me).
But sometimes this (or similar) question is asked when the user wants to comment out a section of code that is currently not working, or someone may even want to do something like: y <- rnorm( n, #if 0 0, 1 #else mu, sigma #endif ) Which would work with a preprocessor, but be more difficult with the run time if statement. But you are correct that for some uses (we don't know what the original poster intends to use this for) a simple run time if statement would work. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Steve Jaffe > Sent: Thursday, August 20, 2009 9:54 AM > To: r-help@r-project.org > Subject: Re: [R] Is there a construct for conditional comment? > > > Why not > > if ( 0 ) { > commented with zero > } else { > commented with one > } > > > 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 > >> > > > > -- > View this message in context: http://www.nabble.com/Is-there-a- > construct-for-conditional-comment--tp25034224p25064798.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. ______________________________________________ R-help@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.