Why does R have two assign operators ``

Clash Royale CLAN TAG#URR8PPPWhy does R have two assign operators `<-` & `->`
I know how to use <- & ->, and there are good writeups on the difference between equals assignment & arrow assignment, but I don't know when to prefer -> over <-.
<-
->
equals
->
<-
It seems the community has coalesced around using <- for assignment.
<-
Neither the google R style-guide, nor Hadley Wickam's tidyverse R style-guide even even mention -> in the assignment section.
->
I'm curious about the design considerations that led the s/s-plus developers to put in the right arrow assign operator ->. In what setting(s) would using -> be considered more readable (or easier to type) versus <- or =.
->
->
<-
=
I'm not familiar with any other language that allows the right-assignment semantics. What languages inspired R in this regard?
1 Answer
1
I think it is just a matter of personal preference.
Although -> predated magrittr pipes, one recent use case is that -> can be used to keep the flow from left to right in such pipes:
->
->
library(magrittr)
input %>% fun1 %>% fun2 -> result
On the other hand, given that <- is mostly used you might want to use <- even in that case.
<-
<-
The argument for <- is that it starts the line off with the value being set which is sort of like the purpose of the statement, particularly if the result variable is well named, whereas the right hand side is the mechanics and so is detail subservient to the result -- and one likes to start off with an overview and then only get into the detail later.
<-
Personally, I never use ->.
->
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Possibly related: softwareengineering.stackexchange.com/questions/98406/…
– MrFlick
34 mins ago