TRUE and FALSE, not T and F

It is common to see code that uses T for TRUE and F for FALSE, but this can lead to unexpected errors. By default, R assumes T and F are TRUE and FALSE. However, these variables are sometimes overwritten, whereas TRUE and FALSE cannot be overwritten. For example, T is occasionally used for a time variable by users; if the first element of T is zero, then there can be serious consequences.
This issue is so severely overlooked that it is common to read a textbook highlighting the use of R and see inappropriate use of T and F.

Example. Below I create a time vector T that starts with 0. In this case, we see a warning, but depending on what the user assigns as T, we may not.
> set.seed(5)
> T <- 0:100
> Y <- rpois(101, exp(T/40))
> png("TRUEFALSE.png")
> plot(T, Y, axes=T)
Warning messages:
1: In if (axes) { :
  the condition has length > 1 and only the first element will be used
2: In if (frame.plot) localBox(...) :
  the condition has length > 1 and only the first element will be used
> lines(T, exp(T/40))
null device 

A scenario where we might not see the warning is if T just marks the current time, and we initialize T at time 0.
Pages for three functions used in the example above:
set.seed, png,
Thank you. Thanks to Jan de Leeuw! This was one of the many things I learned when I took his class during my first year at UCLA Statistics.

Leave a Reply