Re:Introducing R to a non-programmer in one hour
by xerula on Wednesday January 08, 2014 @03:23PM
(#7026299)
Also "=" is compulsory for setting some named function arguments that have a default value. E.g. format(pi, digits <- 16) only prints with the default number of digits, format(pi, digits=16) works as expected. I think it's nice to have a syntax that distinguishes between object and argument assignment.
Also you can do things like this when you're bored:
((a <- b <- 1) + 1 -> c) + 1 -> d
(Someone also once told me that "=" for normal assignment sometimes fails in unexpected ways in tryCatch blocks, but I don't know how or why.)
Re:Introducing R to a non-programmer in one hour
by anaphor on Wednesday January 08, 2014 @12:27PM
(#7024897)
Also, a language shouldn't use the same operator for declaration (initialization in dynamic languages) and assignment imho.
Re:Introducing R to a non-programmer in one hour
by alecdbrooks on Wednesday January 08, 2014 @02:17PM
(#7025788)
Just to be clear, R doesn't ever use the same operator for both, it uses == for comparison like C and Python. That being said, extra differentiation is a bonus.
Re:Introducing R to a non-programmer in one hour
by flyingbrotus on Wednesday January 08, 2014 @12:38PM
(#7024977)
"The operators <- and = assign into the environment in which they are evaluated. 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."
1) Google says so: http://google-styleguide.googlecode.com/svn/trunk/Rguide.xml
2) It's the accepted convention of the language. When she looks things up of SO, they'll use it; if she looks at a package's source, they'll use it.
3) In RStudio it's "option+hypen" (Mac) to type the four-character " <- ", so no extra typing required.
4) Statistically-speaking, things like x = x + 1 makes no sense
5) You need "<<-" for the occasional global
6) 2 -> x