Skip to content

if(foo == TRUE) .. etc

3 messages · Liaw, Andy, Vincent Goulet, Martin Maechler

#
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
#
Le 22 Avril 2005 13:41, Liaw, Andy a ??crit??:
I think it used to be that the situation about T/TRUE and F/FALSE being 
preassigned/reserved was exactly the opposite between R and S-Plus. However, 
in S-Plus 6.1.2 for Linux and S-Plus 6.2.1 for Windows, TRUE and FALSE and 
still preassigned values of T and F, respectively, but one cannot redefine 
them. In other words, TRUE and FALSE are also reserved names in S-Plus.

So, using TRUE and FALSE seems to be a common denominator for R and S-Plus 
(and a sensible choice, for that matter). That's what I teach my students.

Vincent
2 days later
#
Vincent> Le 22 Avril 2005 13:41, Liaw, Andy a ??crit??:
    >> > 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

    Vincent> I think it used to be that the situation about
    Vincent> T/TRUE and F/FALSE being preassigned/reserved was
    Vincent> exactly the opposite between R and S-Plus.

no. that's not true, see below.

    Vincent> However, in S-Plus 6.1.2 for Linux and S-Plus 6.2.1
    Vincent> for Windows, TRUE and FALSE and still preassigned
    Vincent> values of T and F, respectively, but one cannot
    Vincent> redefine them. In other words, TRUE and FALSE are
    Vincent> also reserved names in S-Plus.

That has always been the case.

    Vincent> So, using TRUE and FALSE seems to be a common
    Vincent> denominator for R and S-Plus (and a sensible
    Vincent> choice, for that matter). That's what I teach my
    Vincent> students.

and so ``should'' everyone else.

    Vincent> Vincent

    Vincent> -- Vincent Goulet, Associate Professor ??cole
    Vincent> d'actuariat Universit?? Laval, Qu??bec

Martin Maechler, ETH Zurich