25

I noticed that using T and F instead of TRUE and FALSE in functions in R gives me the same results. Of course, T and F are more concise, yet, I see TRUE and FALSE being used more often.

I was wondering whether there is any difference between the two? Is there anything wrong with using T and F?

Jaap
  • 81,064
  • 34
  • 182
  • 193
Rob
  • 1,460
  • 2
  • 16
  • 23

1 Answers1

34

T and F can be re-defined, but TRUE and FALSE are reserved words and cannot be re-defined.

> TRUE <- 1L
Error in TRUE <- 1L : invalid (do_set) left-hand side to assignment
> FALSE <- 0L
Error in FALSE <- 0L : invalid (do_set) left-hand side to assignment
> T <- F  # yikes, this would be hard to debug!

Personally, I sometimes use T and F when I use R interactively, but I never use them in production code or packages.

Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
  • 7
    Note that in S+ it was the opposite--`T` and `F` were the reserved words and `TRUE` and `FALSE` the variables with defaults. I wish it were that way in R, but c'est la vie. – Ari B. Friedman Aug 15 '13 at 16:11
  • 4
    @AriB.Friedman I believe it was partially the fault of the genetics community, who for some reason like to use "T" for something else. – Carl Witthoft Aug 15 '13 at 17:26
  • 7
    @CarlWitthoft Interesting. Seems like they profited from a pyrimidine scheme. – Ari B. Friedman Aug 15 '13 at 17:28
  • 8
    You're not allowed to use `T` and `F` in cran packages - so if you're going to submit to cran, you'll have to change them anyway. – hadley Aug 15 '13 at 21:43