News for hackers. Stuff that matters.
Re:ARrgh: a newcomer's angry guide to R (2013) by acqq on Sunday December 14, 2014 @07:14PM (#8750083)
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

"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)

Re:ARrgh: a newcomer's angry guide to R (2013) by rcthompson on Sunday December 14, 2014 @08:59PM (#8750364)
Yes, 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(`@!":%$>"@;`)
Re:ARrgh: a newcomer's angry guide to R (2013) by mapcar on Monday December 15, 2014 @06:19AM (#8751455)
and if you overwrite variables like "c", you can always invoke the original concatenation function as "base::c".
Re:ARrgh: a newcomer's angry guide to R (2013) by 0942v8653 on Sunday December 14, 2014 @07:34PM (#8750142)
You don't have to declare a variable before you use it, so there's no such thing as "a new T".
Re:ARrgh: a newcomer's angry guide to R (2013) by acqq on Sunday December 14, 2014 @07:45PM (#8750171)
But can I declare the local t in the function? And is the t in the function parameter local?
Re:ARrgh: a newcomer's angry guide to R (2013) by hadley on Sunday December 14, 2014 @10:54PM (#8750601)
Yes and yes. R is lexically scoped
Re:ARrgh: a newcomer's angry guide to R (2013) by hadley on Sunday December 14, 2014 @10:59PM (#8750615)
It'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
Re:ARrgh: a newcomer's angry guide to R (2013) by a_bonobo on Monday December 15, 2014 @04:18AM (#8751208)
You 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!

Re:ARrgh: a newcomer's angry guide to R (2013) by hadley on Monday December 15, 2014 @04:29PM (#8754581)
There are way worse things you can do than that! e.g.

`(` <- function(x) { if (is.numeric(x) && runif(1) < 0.1) { x * 1.1 } else { x } }

;)

Re:ARrgh: a newcomer's angry guide to R (2013) by a_bonobo on Tuesday December 16, 2014 @12:11PM (#8758010)
That is beautiful, thank you very much! That's the kind of "bug" people don't even notice.