Martin Maechler wrote:> More generally, please, please, everyone : > > Replace > if (something == TRUE) > with if (something) > and > if (something.or.other == FALSE) > with if (!something.or.other)Amen! And right on! And you tell 'em! And a few other exclamations, several of which are not suitable for a family program. That sort of syntax, such as offends Martin's sensibilities (and those of all Right Thinking Persons), appears to issue from the Department of Redundancy Department. cheers, Rolf Turner rolf at math.unb.ca
Great suggestion; it made me change all my Ts/Fs to TRUE/FALSE. Given F <- TRUE T <- FALSE is it possible to forbid T to stand for TRUE, and F for FALSE in function(...,something=T)? Or, alternatively, never allow F <- whatever and T <- whatever? I don't know what the technical side is, but I think it would be much better if this particular blunder (major, yet rather easy to overlook) was impossible to make. -----Original Message----- From: Martin Maechler [mailto:maechler at stat.math.ethz.ch] Sent: Wednesday, April 20, 2005 8:31 AM To: R-help at stat.math.ethz.ch Subject: [R] if(foo == TRUE) .. etc>>>>> "Andy" == Andy Bunn <abunn at whrc.org> >>>>> on Tue, 19 Apr 2005 10:27:04 -0400 writes:..... Andy> is.tuesday <- as.POSIXlt(Sys.time())$wday == 2 Andy> if (is.tuesday == T) { ....} ..... aaah, this really hurts my eyes or rather the brain behind! And it's by far not the first such instance... Rather use " if (is.tuesday) { .... } " More generally, please, please, everyone : Replace if (something == TRUE) with if (something) and if (something.or.other == FALSE) with if (!something.or.other) {and even more for cases where you have 'T' and 'F' instead of 'TRUE' and 'FALSE' - which is against all recommendations, since F <- TRUE T <- FALSE are valid statements, probably not common, but think what happens when you accidentally have the equivalent of "T <- 0" somewhere in your global enviroment! } Martin Maechler, ETH Zurich ______________________________________________ R-help at 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
On Fri, 22 Apr 2005, bogdan romocea wrote:> Great suggestion; it made me change all my Ts/Fs to TRUE/FALSE. > Given > F <- TRUE > T <- FALSE > is it possible to forbid T to stand for TRUE, and F for FALSE in > function(...,something=T)? > Or, alternatively, never allow F <- whatever and T <- whatever? >Allowing T and F to be used as variables is deliberate. R CMD check will check to see if you use T and F without defining them, which catches most examples. This is done using makeActiveBinding, see the help to find out how you can use it yourself. -thomas
> From: bogdan romocea > > Great suggestion; it made me change all my Ts/Fs to TRUE/FALSE. > Given > F <- TRUE > T <- FALSE > is it possible to forbid T to stand for TRUE, and F for FALSE in > function(...,something=T)? > Or, alternatively, never allow F <- whatever and T <- whatever? > > I don't know what the technical side is, but I think it would be much > better if this particular blunder (major, yet rather easy to overlook) > was impossible to make.R FAQ 3.3, bullet #3: In R, T and F are just variables being set to TRUE and FALSE, respectively, but are not reserved words as in S and hence can be overwritten by the user. (This helps e.g. when you have factors with levels "T" or "F".) Hence, when writing code you should always use TRUE and FALSE. If T and F are changed as you suggested above, it will break S compatibility in lots of code. Andy> > -----Original Message----- > From: Martin Maechler [mailto:maechler at stat.math.ethz.ch] > Sent: Wednesday, April 20, 2005 8:31 AM > To: R-help at stat.math.ethz.ch > Subject: [R] if(foo == TRUE) .. etc > > > >>>>> "Andy" == Andy Bunn <abunn at whrc.org> > >>>>> on Tue, 19 Apr 2005 10:27:04 -0400 writes: > > ..... > Andy> is.tuesday <- as.POSIXlt(Sys.time())$wday == 2 > Andy> if (is.tuesday == T) { ....} > ..... > > aaah, this really hurts my eyes or rather the brain behind! > And it's by far not the first such instance... > > Rather use " if (is.tuesday) { .... } " > > More generally, please, please, everyone : > > Replace > if (something == TRUE) > with if (something) > and > if (something.or.other == FALSE) > with if (!something.or.other) > > {and even more for cases where you have > 'T' and 'F' instead of 'TRUE' and 'FALSE' - > which is against all recommendations, since > F <- TRUE > T <- FALSE > are valid statements, probably not common, but think what > happens when you accidentally have the equivalent of "T <- 0" > somewhere in your global enviroment! > } > > Martin Maechler, ETH Zurich > > ______________________________________________ > R-help at 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 > > > ______________________________________________ > R-help at 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 > > >