10 thoughts on ““Rbitrary Standards”

  1. I guess the FAQ starts with the topic of `<-` so you know it's an April Fools joke. I appreciate satire as much as the next guy, but something calling itself a FAQ might want to point out that there are three different uses for an "equals" in R and in other languages, and each has handled it differently. (Including not allowing one of the uses in certain situations.) Stopped reading at that point.

    • Strictly speaking it stars with “Why do we use <- for assignment?", which is only one of the uses of "<-" and is discussed accurately, but they do have a section about how to contact the complaints department.

    • I actually think this discussion of the history of how things came about can be useful. It helps build your mental model of the language to know WHY not just HOW. Anyway, I thought it was not only cute but useful and wish it had about 5 or 6 more topics. I particularly liked the bit about how evaluation is optional. I’d also like to know how the heck does ggplot2 work really because I’m always getting burned by evaluation in that context.

      • The problem is that the author went for sarcastic rather than accurate, so only told part of the story.

        The reason the particular symbol `<-` was chosen may have something to do with APL, but the more important concept is why the authors might've even thought some symbol (other than the obvious `=`) might've been required. And this has to do with the idea that there are three kinds of "equals" in languages:

        1. Assignment
        2. Comparison
        3. Naming

        Some languages do not have #3, or use a different symbol.

        As an example, C does not have named variables, but does allow assignment in a function call, so it's perfectly legitimate to:

        foo (x = sin (y), 45) ;

        where the `x=sin (y)` is an assignment: the results of `sin (y)` are calculated and the result is put into the variable x, as if you had done:

        x = sin (y) ; foo (x, 45)

        You can also do this in R, so there's a fundamental issue with:

        foo (x = sin (y)) versus foo (x <- sin (y))

        where the second example corresponds to the C code, above. And what happens in the first case if `x` isn't a parameter in the function `foo`?

        Since R has first-class expressions, it's very R-like to do something like:

        system.time (bar <- foo (x = sin (y)))

        expecting that it's clear what's going on: we're wrapping `system.time` around an expression that is an assignment, not passing a variable by name.

        Other languages have used symbols like `:=` for assignment, and most languages have adopted the C-like `==` for comparison, though earlier languages used things like `.EQ.`, `EQ`, or `EQUAL` for comparisons. Other languages don't have named arguments. Other languages disallow assignments in function calls (and control statements like `if (x = foo () == -1)`). I could imagine using a single colon to indicate a parameter name (like `foo (x:bar)`), but then R uses colons to indicate environments. The bottom line is that R was ahead of the curve in terms of expressive power, having the three types of "equals" and chose to distinguish the three with different symbols.

        So the `=` for assignment was added because of people like the "FAQ" writer who didn't bother to understand distinctions and thought it was because of APL or S or some other obscure thing. And it adds confusion to the language, which is then criticized by "FAQ" writers.

      • I’m not sure it will solve your problems with ggplot2 (I don’t know what problems you’re having …), but I would say that the chapter on “non-standard evaluation” in Hadley Wickham’s _Advanced R_ book is a good place to start: http://adv-r.had.co.nz/Computing-on-the-language.html (I would include it as a proper link but I always seem to get that wrong). It’s more pedagogical (and IMO more useful) than the http://developer.r-project.org/nonstandard-eval.pdf document suggested by “Rbitrary Standards”

        Last suggested on this site a few months ago, Pat Burns’s “R Inferno” (http://www.burns-stat.com/documents/books/the-r-inferno/) (“If you are using R and you think you’re in hell, this is a map for you”) is very useful, although a lot of it is general stuff that may already be known to readers here. His “Inferno-ish R” (http://www.burns-stat.com/pages/Present/infernoishR_annotated.pdf) is an interesting historical perspective from someone who started using S in 1984 …

Leave a Reply

Your email address will not be published. Required fields are marked *