shameless plug: My book R Graph Cookbook is out soon - https://www.packtpub.com/r-graph-cookbook/book. It contains recipes for doing things with graphs, which can sometimes be obscure, annoying and time consuming.
Using '<-' is the general style of the R community. The accepted (but not universal) practice is to use '<-' for assignment and '=' in argument passing. This is a good idea because '<-' and '=' are not equivalent and '<-' is more likely the operator you want. From the help page [1] The operator ‘<-’ can be used anywhere, whereas the operator ‘=’ is only allowed at the top level (e.g., in the complete expression typed at the command prompt) or as one of the subexpressions in a braced list of expressions. That being said, some R community members still use '=' for assignment, but it's frowned upon. It certainly annoys me when I see it in R code.
Simple example to show when '=' won't work but '<-' will. Pilfered from "R Inferno" [2], which is an excellent reference for R idioms and best practices.
I've added some examples to my above comment. My example is perhaps a little closer to 'median(x <- 10)' than you were asking for, but I think it illustrates the point that using '=' will not always have the desired result in places where '<-' would.
My understanding has always been that <- is the way that S did it, so that's the way R originally did it but = is almost always equivalent. I haven't found a place in my modest R hacking yet that = hasn't worked the way I expected it to...
And I haven't found anything in my ten years of using R in statistical analysis where '=' didn't work either. I've written a lot of R code. A hedge process on €2bn is being monitored with '=' signs as we speak. Dastardly.
13 comments
[ 289 ms ] story [ 814 ms ] thread(if there already is on the site you linked to, sorry for being obtuse).
Simple example to show when '=' won't work but '<-' will. Pilfered from "R Inferno" [2], which is an excellent reference for R idioms and best practices.
And to demonstrate that you need to use '=' for argument passing: [1] Type help('=') at an R prompt, or view it online: http://stat.ethz.ch/R-manual/R-patched/library/base/html/ass...[2] http://www.burns-stat.com/pages/Tutor/R_inferno.pdf
edit: clarified statement.
edit: added examples.
Do you have an example of where it would be required to use '<-'? Not just median(x <- 10), but a use in which there no simple '=' alternative.
This applies in all languages:
vec1 = rnorm(100)
system.time(vec1)
mean(vec1)
And, I can get my colleagues to fix it when I screw up, even though they are not R-heads.