I understand that R highlights specific text depending on its function, but what does it mean when the variable you are assigning is highlighted? And can it cause any problems? For example, T
is highlighted automatically in:

- 211,554
- 25
- 370
- 453

- 35
- 5
-
`T` is a logical value that means `TRUE` – Duck Jul 19 '20 at 19:00
2 Answers
It is better not to use T
in R as a variable. The reason T
is highlighted is that it is used as an abbreviation for TRUE
. If you use T
as a variable, you can no longer use it as TRUE
and its definition will be overwritten.

- 211,554
- 25
- 370
- 453

- 1,945
- 1
- 9
- 17
-
3No, `t` transposes a matrix. `T` is a variable name which by default is assigned to `TRUE` but can be overwritten. Similarly `F` is a synonym for `FALSE` – Allan Cameron Jul 19 '20 at 19:03
-
You could also link to [this blog post](https://www.r-bloggers.com/r-tip-avoid-using-t-and-f-as-synonyms-for-true-and-false/) for an example of why it is best to avoid using `T` and `F` as synonyms for TRUE/FALSE (and by extension avoid using T as a variable name as well ...) – Ben Bolker Jul 19 '20 at 19:12
-
people are fast here, I fixed it a min after I posted, then I saw the comment, I didn't pay attention to question enough – Reza Jul 19 '20 at 19:25
You've been told not to use T
as a variable name but you've not yet been given an answer to your question. It's not really an issue of R syntax, but rather a "feature" of whatever IDE you are using. Most IDEs are syntax aware and will therefore highlight in blue items that are meaningful inside the R language. If you run R from a Terminal session you would not see the highlighting.
If you need that feature you can get a package: highlighting
Description: Syntax highlighter for R code based on the results of the R parser. Rendering in HTML and latex markup. Custom Sweave driver performing syntax highlighting of R code chunks.

- 258,963
- 21
- 364
- 487
-
1good information (although "The reason T is highlighted is that it is used as an abbreviation for TRUE" is, technically, an answer to the question ...) – Ben Bolker Jul 19 '20 at 21:37
-
1the `highlighting` package will give you syntax highlighting **in Sweave/LaTeX output**, not in the terminal. Apparently `colorout` would work ... https://stackoverflow.com/questions/14355369/r-syntax-highlighting-in-terminal – Ben Bolker Jul 19 '20 at 21:48