4 ms·
Wow, the language used to code formulas in which it's dangerous to use the single-letter variables: http://tim-smith.us/arrgh/atomic.html http://tim-smith.us/a
by acqq 12y ago
Wow, the language used to code formulas in which it's dangerous to use the single-letter variables:
http://tim-smith.us/arrgh/atomic.html http://tim-smith.us/arrgh/atomic.html
"This also means that you shouldn't ever assign useful quantities to variables named T and F. Sorry. Other variable names that you cannot use are c, q, t (!), C, D, and I."
Note the contradiction of that limitation and the name of the language. Makes the name even more exceptional.
Is he right? What's with the scope? Can't I introduce a new T in my function thus just hiding the global one from it, but otherwise not disturbing anything? (I don't know R, I'm just asking, reading that the variables have the function scope)
- 0942v8653 12y agoYou don't have to declare a variable before you use it, so there's no such thing as "a new T".
- rcthompson 12y agoYes, all those single-letter names are just ordinary variables that you can overwrite. Doing so is nearly always a terrible idea. The article is being a little unclear when it says "cannot use". You can use literally any variable name in R if you really want to. If the name you want is already a reserved word (e.g. "for", "else", "function"), or if it is not a syntactically valid token (e.g. '@!":%$>"@;'), then you just have to enclose it in backquotes. So the following is valid R: `for` <- 1:5 `function` <- 5:1 `TRUE` <- `for` / `function` `@!":%$>"@;` <- `TRUE`^2 print(`@!":%$>"@;`)
- mapcar 12y agoand if you overwrite variables like "c", you can always invoke the original concatenation function as "base::c".
- hadley 12y agoIt's not really as bad as all that. The reason to avoid using those names is to avoid confusing the reader, not because it causes problems for R
- a_bonobo 12y agoYou can cause some mischief - if you write a package, or distribute a .Rprofile to colleagues, you can hide somewhere in there a temp <- F F <- T T <- temp and if your colleagues are lazy and use T and F (instead of TRUE and FALSE) fun and very gnarly to debug things are going to happen! Nichts ist wahr! Alles ist erlaubt!