r assignment arrow or equal

Secure Your Spot in Our R Programming Online Course - Register Until Nov. 27 (Click for More Info)

Joachim Schork Image Course

Assignment Operators in R (3 Examples) | Comparing = vs. <- vs. <<-

On this page you’ll learn how to apply the different assignment operators in the R programming language .

The content of the article is structured as follows:

Let’s dive right into the exemplifying R syntax!

Example 1: Why You Should Use <- Instead of = in R

Generally speaking, there is a preference in the R programming community to use an arrow (i.e. <-) instead of an equal sign (i.e. =) for assignment.

In my opinion, it makes a lot of sense to stick to this convention to produce scripts that are easy to read for other R programmers.

However, you should also take care about the spacing when assigning in R. False spacing can even lead to error messages .

For instance, the following R code checks whether x is smaller than minus five due to the false blank between < and -:

A properly working assignment could look as follows:

However, this code is hard to read, since the missing space makes it difficult to differentiate between the different symbols and numbers.

In my opinion, the best way to assign in R is to put a blank before and after the assignment arrow:

As mentioned before, the difference between <- and = is mainly due to programming style . However, the following R code using an equal sign would also work:

In the following example, I’ll show a situation where <- and = do not lead to the same result. So keep on reading!

Example 2: When <- is Really Different Compared to =

In this Example, I’ll illustrate some substantial differences between assignment arrows and equal signs.

Let’s assume that we want to compute the mean of a vector ranging from 1 to 5. Then, we could use the following R code:

However, if we want to have a look at the vector x that we have used within the mean function, we get an error message:

Let’s compare this to exactly the same R code but with assignment arrow instead of an equal sign:

The output of the mean function is the same. However, the assignment arrow also stored the values in a new data object x:

This example shows a meaningful difference between = and <-. While the equal sign doesn’t store the used values outside of a function, the assignment arrow saves them in a new data object that can be used outside the function.

Example 3: The Difference Between <- and <<-

So far, we have only compared <- and =. However, there is another assignment method we have to discuss: The double assignment arrow <<- (also called scoping assignment).

The following code illustrates the difference between <- and <<- in R. This difference mainly gets visible when applying user-defined functions .

Let’s manually create a function that contains a single assignment arrow:

Now, let’s apply this function in R:

The data object x_fun1, to which we have assigned the value 5 within the function, does not exist:

Let’s do the same with a double assignment arrow:

Let’s apply the function:

And now let’s return the data object x_fun2:

As you can see based on the previous output of the RStudio console, the assignment via <<- saved the data object in the global environment outside of the user-defined function.

Video & Further Resources

I have recently released a video on my YouTube channel , which explains the R syntax of this tutorial. You can find the video below:

The YouTube video will be added soon.

In addition to the video, I can recommend to have a look at the other articles on this website.

  • R Programming Examples

In summary: You learned on this page how to use assignment operators in the R programming language. If you have further questions, please let me know in the comments.

assignment-operators-in-r How to use different assignment operators in R – 3 R programming examples – R programming language tutorial – Actionable R programming syntax in RStudio

Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe. I hate spam & you may opt out anytime: Privacy Policy .

Leave a Reply Cancel reply

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

Post Comment

Joachim Schork Statistician Programmer

I’m Joachim Schork. On this website, I provide statistics tutorials as well as code in Python and R programming.

Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe. I hate spam & you may opt out anytime: Privacy Policy .

Related Tutorials

Get All Factor Levels of Vector & Data Frame Column in R (2 Examples)

Get All Factor Levels of Vector & Data Frame Column in R (2 Examples)

Test for Prime Number in R (Example)

Test for Prime Number in R (Example)


R news and tutorials contributed by hundreds of R bloggers

Why do we use arrow as an assignment operator.

Posted on September 23, 2018 by Colin Fay in R bloggers | 0 Comments

[social4i size="small" align="align-left"] --> [This article was first published on Colin Fay , and kindly contributed to R-bloggers ]. (You can report issue about the content on this page here ) Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

A Twitter Thread turned into a blog post.

In June, I published a little thread on Twitter about the history of the <- assignment operator in R. Here is a blog post version of this thread.

Historical reasons

As you all know, R comes from S. But you might not know a lot about S (I don’t). This language used <- as an assignment operator. It’s partly because it was inspired by a language called APL, which also had this sign for assignment.

But why again? APL was designed on a specific keyboard, which had a key for <- :

At that time, it was also chosen because there was no == for testing equality: equality was tested with = , so assigning a variable needed to be done with another symbol.

r assignment arrow or equal

From APL Reference Manual

Until 2001 , in R, = could only be used for assigning function arguments, like fun(foo = "bar") (remember that R was born in 1993). So before 2001, the <- was the standard (and only way) to assign value into a variable.

Before that, _ was also a valid assignment operator. It was removed in R 1.8 :

r assignment arrow or equal

(So no, at that time, no snake_case_naming_convention)

Colin Gillespie published some of his code from early 2000 , where assignment was made like this 🙂

The main reason “equal assignment” was introduced is because other languages uses = as an assignment method, and because it increased compatibility with S-Plus.


Nowadays, there are seldom any cases when you can’t use one in place of the other. It’s safe to use = almost everywhere. Yet, <- is preferred and advised in R Coding style guides:

  • https://google.github.io/styleguide/Rguide.xml#assignment
  • http://adv-r.had.co.nz/Style.html

One reason, if not historical, to prefer the <- is that it clearly states in which side you are making the assignment (you can assign from left to right or from right to left in R):

The RHS assignment can for example be used for assigning the result of a pipe

Also, it’s easier to distinguish equality comparison and assignment in the last line of code here:

Note that <<- and ->> also exist:

And that Ross Ihaka uses = : https://www.stat.auckland.ac.nz/~ihaka/downloads/JSM-2010.pdf


There are some environment and precedence differences. For example, assignment with = is only done on a functional level, whereas <- does it on the top level when called inside as a function argument.

In the first code, you’re passing x as the parameter of the median function, whereas the second one is creating a variable x in the environment, and uses it as the first argument of median . Note that it works because x is the name of the parameter of the function, and won’t work with y :

There is also a difference in parsing when it comes to both these operators (but I guess this never happens in the real world), one failing and not the other:

It is also good practice because it clearly indicates the difference between function arguments and assignation:

And this weird behavior:

Little bit unrelated but

I love this one:

Which of course is not doable with = .

Other operators

Some users pointed out on Twitter that this could make the code a little bit harder to read if you come from another language. <- is use “only” use in F#, OCaml, R and S (as far as Wikipedia can tell). Even if <- is rare in programming, I guess its meaning is quite easy to grasp, though.

Note that the second most used assignment operator is := ( = being the most common). It’s used in {data.table} and {rlang} notably. The := operator is not defined in the current R language, but has not been removed, and is still understood by the R parser. You can’t use it on the top level:

But as it is still understood by the parser, you can use := as an infix without any %%, for assignment, or for anything else:

You can see that := was used as an assignment operator https://developer.r-project.org/equalAssign.html :

All the previously allowed assignment operators (

Or in R NEWS 1:

r assignment arrow or equal

  • Around 29’: https://channel9.msdn.com/Events/useR-international-R-User-conference/useR2016/Forty-years-of-S
  • What are the differences between “=” and “
  • Assignment Operators

To leave a comment for the author, please follow the link and comment on their blog: Colin Fay . R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job . Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Copyright © 2022 | MH Corporate basic by MH Themes

Never miss an update! Subscribe to R-bloggers to receive e-mails with the latest R posts. (You will not see this message again.)

  • book review

The difference between <- and = assignment in R

  • May 5, 2020 April 5, 2021

When I started coding in R, a couple of years ago, I was stunned by the assignment operator. In most — if not all — coding languages I know, assignment is done through the equal sign ‘=’, while in R, I was taught to do it through the backarrow ‘<-‘. It didn’t take long until I realized the equal symbol also works. So… what is correct?

Let’s say we would like to assign the value 3 to the variable x. There’s multiple ways to do that.

The first five lines of code do exactly the same. The last one is slightly different. The assign function is the OG here: it assigns a value to a variable, and it even comes with more parameters that allow you to control which environment to save them in. By default, the variable gets stored in the environment it is being run in.

The arrows are respectively the leftwards assignment and the rightwards assignment. They simply are shortcuts for assign() . The double arrow in the last line is somewhat special. First, it checks if the variable already exists in the local environment, and if it doesn’t, it will store the variable in the global environment (.GlobalEnv). If you are unfamiliar with this, try reading up on scope in programming.

So why the arrow? Apparently, this is legacy from APL , a really old programming language. R (created in the early nineties) is actually a modern implementation of S (created in the mid-70’s), and S is heavily influenced by APL. APL was created on an Execuport, a now antique machine with a keyboard that had an “arrow” symbol, and it could be generated with one keystroke.

Historically, the = symbol was used to pass arguments to an expression. For example

In 2001, to bring assignment in R more in line with other programming languages, assignment using the = symbol was implemented. There are restrictions, however. According to the documentation , it can only be used at the top-level environment, or when isolated from the surrounding logical structure (e.g. in a for loop).

But this is not necessarily true. By putting brackets around an assignment, in places where intuitively it shouldn’t work, one can get around these restrictions. There’s probably not many use cases where you would want it, but it does work. In the following example, I calculate the mean of 3, 20 and 30 and at the same time assign 3 to x.

My personal advice is to use <- for assignment and = for passing arguments. When you mix things up, weird things can happen. This example from R Inferno produces two different results.

By the way, if two keystrokes really bug you. There’s a shortcut in RStudio to generate the arrow: Alt + -. Well yes, shortcut? You still need to press two keys ;-).

By the way, if you’re having trouble understanding some of the code and concepts, I can highly recommend “An Introduction to Statistical Learning: with Applications in R”, which is the must-have data science bible . If you simply need an introduction into R, and less into the Data Science part, I can absolutely recommend this book by Richard Cotton . Hope it helps!

Great success!

Say thanks, ask questions or give feedback

Technologies get updated, syntax changes and honestly… I make mistakes too. If something is incorrect, incomplete or doesn’t work, let me know in the comments below and help thousands of visitors.

Leave a Reply Cancel reply

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

Related Posts

Starting a remote selenium server in r.

  • June 9, 2023 June 9, 2023

In this brief article, I explain how you can run a Selenium server, right from within your R code. This allows you to not manually… 

How to set the package directory in R

  • April 10, 2021 April 10, 2021

When I got my new company computer, out service desk installed R in a network folder, which made installing and loading R libraries extremely slow.… 

Counting, adding or subtracting business days in R

  • March 22, 2021 March 22, 2021

Calculating the number of days between two dates in R is as simple as using + or -. However, if you only want to count… 

Protect yourself from equals assignment!

March 13, 2021

A man sits at a table with a banner that has on it R's left assignment operator (<-) and underneath it says 'change my mind'.

I present you a function that warns if an R script contains The Assignment Operator That Shall Not Be Named .

Assign of the times

So, it’s been confirmed with extremely robust and objective evidence : the left-assignment arrow ( x <- 1 ) is better than equals ( x = 1 ) for assignment in R. 1

So, unless you hate democracy, you should protect yourself from aberrant code that uses the cursed symbol.

But what if a nefarious colleague still sends you their scuffed code?

Assignment refinement

I’ve created the appraise_assignment() function that will peek at a suspect script and warn you if it contains the foul mark.

Basically, we parse() an input file and then the function uses getParseData() to extract ‘tokens’ (i.e. maths symbols, special operators, variables, etc) from the R expressions within.

In particular, it spots the token called EQ_ASSIGN , which is when = is used in the context of assignment.

I saw the assign

For demonstration purposes, I’ve written four temporary files containing left assign ( <- ), right assign ( -> ), equals ( = ), and no assignment at all. 2 Our function will catch even a single deviation in a given file.

First, let’s pass the file containing the unquestionably correct assignment operator.

Right-assignment is left-assignment’s less-handsome sibling.

Hold steady…

Phew, we got a warning, so we know the file is dangerous and should never be opened.

In fact, if you set the argument destroy = TRUE in appraise_assignment() , you’ll be prompted to irrecoverably annihilate the rotten file forever. 3

For completeness, is it really an R script if it doesn’t contain any assignment at all?

Assigning off

In conclusion, some assignment operators were created more equal than others. See Colin Fay’s round-up to learn more about the history and plethora of these symbols (and be happy that the underscore is no longer legitimate).

Anyway, welcome to the best timeline, where we all recognise <- unequivocally as the champion and = can get absolutely rekt.

If I had one wish though, it would be to make the left-assign arrow even more powerful. How about making it really long? 23 hyphens seems sufficiently dominant.

It’s a really long arrow, so I call it ‘the spear’. 4 I look forward to its adoption by R Core.


Actually, I don’t really care which one you use, but that’s less of a funny take. I prefer the left assignment operator because look! It’s a little arrow! Quirky! Esoteric! An extra keystroke to exercise your fingers! ↩︎

We do not talk about <<- . ↩︎

Well, not really, because I don’t want you to delete any of your files. But rest assured I’ve included file.remove() in my local version of the function and I’m not afraid to use it. ↩︎

In other words, R evaluates this as an object, x , being assigned a numeric value that has an odd number of ‘negative’ symbols that cancel each other out. ↩︎

Blog of Ken W. Alger

Just another Tech Blog

Blog of Ken W. Alger

Assignment Operators in R – Which One to Use and Where

r assignment arrow or equal

Assignment Operators

R has five common assignment operators:

Many style guides and traditionalists prefer the left arrow operator, <- . Why use that when it’s an extra keystroke?  <- always means assignment. The equal sign is overloaded a bit taking on the roles of an assignment operator, function argument binding, or depending on the context, case statement.

Equal or “arrow” as an Assignment Operator?

In R, both the equal and arrow symbols work to assign values. Therefore, the following statements have the same effect of assigning a value on the right to the variable on the left:

There is also a right arrow, -> which assigns the value on the left, to a variable on the right:

All three assign the  value of forty-two to the  variable   x .

So what’s the difference? Are these assignment operators interchangeable? Mostly, yes. The difference comes into play, however, when working with functions.

The equal sign can also work as an operator for function parameters.

x <- 42 y <- 18 function(value = x-y)

History of the <- Operator

r assignment arrow or equal

The S language also didn’t have == for equality testing, so that was left to the single equal sign. Therefore, variable assignment needed to be accomplished with a different symbol, and the arrow was chosen.

There are some differences of opinion as to which assignment operator to use when it comes to = vs <-. Some believe that = is more clear. The <- operator maintains backward compatibility with S.  Google’s R Style Guide recommends using the <- assignment operator, which seems to be a pretty decent reason as well. When all is said and done, though, it is like many things in programming, it depends on what your team does.

r assignment arrow or equal

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to email a link to a friend (Opens in new window)
  • Click to print (Opens in new window)

Leave a Reply Cancel reply

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

Notify me of follow-up comments by email.

Notify me of new posts by email.

This site uses Akismet to reduce spam. Learn how your comment data is processed .

November 16, 2010

Assignment operators in r: ‘=’ vs. ‘<-‘.

In R, you can use  both ‘=’ and ‘<-‘ as assignment operators. So what’s the difference between them and which one should you use?

What’s the difference?

The main difference between the two assignment operators is scope. It’s easiest to see the difference with an example: ##Delete x (if it exists) > rm(x) > mean(x=1:10) #[1] 5.5 > x #Error: object 'x' not found Here x is declared within the function’s scope of the function, so it doesn’t exist in the user workspace. Now, let’s run the same piece of code with using the <- operator: > mean(x <- 1:10)# [1] 5.5 > x # [1] 1 2 3 4 5 6 7 8 9 10 This time the x variable is declared within the user workspace.

When does the assignment take place?

In the code above, you may be tempted to thing that we “assign 1:10 to x, then calculate the mean.” This would be true for languages such as C, but it isn’t true in R. Consider the following function: > a <- 1 > f <- function(a) return(TRUE) > f <- f(a <- a + 1); a [1] TRUE [1] 1 Notice that the value of a hasn’t changed! In R, the value of a will only change if we need to evaluate the argument in the function. This can lead to unpredictable behaviour: > f <- function(a) if(runif(1)>0.5) TRUE else a > f(a <- a+1);a [1] 2 > f(a <- a+1);a [1] TRUE [1] 2 > f(a <- a+1);a [1] 3

Which one should I use

Well there’s quite a strong following for the “<-” operator:

  • The Google R style guide prohibits the use of “=” for assignment.
  • Hadley Wickham’s style guide recommends “<-“
  • Update Following a comment from David Smith below, it seems that S-plus now accepts “=”.
  • I believe that the General R community recommend using “<-” – see for example this link in the mailing list .

However, I tend always use the “=” operator for the following reasons:

  • The other languages I program in (python, C and occasionally JavaScript) use the “=” operator.
  • It’s quicker to type “=” and “<-“.
  • Typically, when I type declare a variable – I only want it to exist in the current workspace.
  • Since I have the pleasure of teaching undergraduates their first course in programming, using “=” avoids misleading expressions like if (x[1]<-2)

Also Introducing Monte Carlo Methods with R , by Robert and Casella recommends using “=”.

If I’m missing something or you disagree, please leave a comment – I would be very interested.

  • Stackoverflow question
  • The R manual’s description of assignment operators
  • A useful discussion on the R mailing list
  • Update :  Discussion of why R uses “<-“. From the revolution analytics blog.

Share this:


' src=

Nice post! To be pedantic though, “=” and “<-" have the same scope; it's just that the "=" operator is overloaded for both parameter association (in function calls) and assignment. I believe "=" is a valid assignment operator in S+ now, too.

You might be interested in the history of *why* R uses <- for assignment, as referenced here: http://blog.revolutionanalytics.com/2008/12/use-equals-or-arrow-for-assignment.html

Comment by David Smith — November 16, 2010 @ 10:09 pm

' src=

Nothing wrong with being pedantic – that’s why we’re interested in computing! Do you have a reference for the operator overloading bit?

Thanks for link. I still have some old R scripts laying around that uses the “underscore” for assignment. Any idea how that fits into the grand scheme of things?

Comment by csgillespie — November 16, 2010 @ 10:17 pm

You’d need to convert those _ characters to <- or =. Underscore was deprecated as an assignment operator in R a long time ago. Now it's a valid character in object_names.

Comment by David Smith — November 16, 2010 @ 10:34 pm

Sorry, I wasn’t being clear (I realise that I just have to change “_” to “=”). What I meant was why did they use “_” in the first place and what brought about the change?

I suppose that it was because S+ used “_”.

Comment by csgillespie — November 17, 2010 @ 10:05 am

' src=

It’s worth mentioning that you can also use -> for example: 1 + 2 -> a sometimes useful especially when using arrow up to find previous line and then assign value/object, example: lm(y~x)-> a

Comment by Peter Cahusac — November 16, 2010 @ 10:36 pm

Good point. Although I’ve started using emacs+ESS more and more. Thereby reducing the need to (directly) use the R terminal.

Comment by csgillespie — November 17, 2010 @ 10:07 am

' src=

I’ve grown used to the <- operator and it's much easier to read the code using that. I sometimes get code from other people who use =, and it helps readability a lot if I change = to <-.

And regarding the ease of typing = over <-: depends on your keyboard layout, I guess. I use Slovenian layout and I find it easier to write <- than =.

Comment by Roman Luštrik — November 17, 2010 @ 12:07 am

I think “grown used to it” seems to be the main argument for using “<-". I didn't really use R from 2002-2008, so when I started using it again, "_" no longer worked. So I changed to using "="

Comment by csgillespie — November 17, 2010 @ 10:09 am

' src=

I simply find it more pleasing to the eye than =.

Comment by romunov — November 17, 2010 @ 10:12 am

' src=

I use ‘<-' to assign variables, and '=' to assign arguments within functions:


I find it makes the code easier to read. Once you get used to typing '<-' you don't even notice the difference.

Comment by Frank — November 17, 2010 @ 5:49 am

I think that’s what the majority of users do.

Comment by csgillespie — November 17, 2010 @ 10:10 am

' src=

It’s actually the place when you see the biggest difference between `<-` and `=`. You could do test <- function(a,b) a+b test(x<-1,y<-2) which creates x and y variables in workspace, whilst test(x=1,y=2) gives you an error.

Comment by Marek — November 17, 2010 @ 3:33 pm

' src=

Thanks for the post! Mostly, I prefer using = to <- for purely esthetic reasons! (I also had a traumatic experience with _ in the old S-plus days where I renamed variables and removed all _…) The other reason is that most languages use = as an assignment and this sounds good enough… Actually, I remember getting a comment at some point that we should have used <- in Introducing Monte Carlo Methods with R but I cannot trace it back.

Comment by xi'an — November 17, 2010 @ 6:38 am

I agree. I think “=” just looks nicer. However, “Beauty is in the eye of the beholder” !

Comment by csgillespie — November 17, 2010 @ 10:16 am

' src=

It gives me hope that even regular users of R find the semantics of the language a little confusing. I’ve been trying to get to grips with it for ages (at the same time as trying to lift my stats knowledge above it’s current risible level). But I find it very difficult to understand exactly what the language does.

Still, it’s not so bad. Not compared to “underscore as assignment operator”.

Comment by Phil Lord — November 17, 2010 @ 11:38 am

I’m trying to imagine the arguments that must have occured in the R-mailing list when they suggested adding the “=” operator. Perhaps a bit of googling can find them 😉

Comment by csgillespie — November 17, 2010 @ 11:41 am

' src=

I didn’t like ‘<-' at first. Now I strongly support it as a convention.

I think the main advantage is conceptual clarity. There is no ambiguity that the operation is assigning a property to an object. You can read it as "object x gets the value y." It has directionality. When you type "x = y" it isn't clear which is taking the value of the other. As example, "3 = x" could be interpreted as the number 3 being assigned the letter x. We only know that is not the case because of the less obvious convention that the object on the left is changed by assignment.

Comment by Harold Baize — November 17, 2010 @ 5:48 pm

In some sense I completely agree with you. However,

  • When you do a function call, you would often write: f(x=y) . Is that not confusing?
  • No one would/should write “3=x” (or 3 <- x)!
  • I suspect that when you say “x=y” isn’t clear, you have never actually been confused 😉
  • I tend to programme in a few languages. I already hate having to remember the syntax for: if statements, functions, objects for different languages. Case in point: I’m forever typing i++ in R code!

As I mentioned, I do agree with you. It’s just that R is a special case and I don’t want to change for a special case.

Comment by csgillespie — November 17, 2010 @ 6:01 pm

' src=

As David Smith noted, mean(x = 1:10) is not assignment but parameter association. However, mean(a <- 1:10) works as expected, but mean(a = 1:10) does not. The latter because there is no parameter "a" and "=" is not interpreted as the assignment operator. To make it behave like that, you will need to brace the expression, like mean({a = 1:10}) cf. the help page. It's the only real difference I know about, and as noted on the first blog-link David posted, you probably don't want to assign variables in a function call anyway.

My reason to support and use "<-" is purely conceptual. Assignment is an oriented operation, which is not conveyed by the symmetric looking "=". Even though R may be a special case, it is good when the syntax supports the line of thought, and we should take advantage of this in R instead of trying to turn it into C-code.

Comment by Niels Hansen — November 17, 2010 @ 6:59 pm

True that one should never write “3 = x” or “3 <- x" and both return an error message.

Although I can't recall ever confusing the meaning of "x = y" the syntax "x <- y" is more intuitive, and I like things to make sense. For me it is worth the extra keystroke to be explicit and clear.

Comment by Harold Baize — November 17, 2010 @ 7:02 pm

' src=

See also the discussion of this on Stack Overflow from last year, which covers much of the same ground.

Comment by richierocks — November 24, 2010 @ 5:15 pm

I had already included the link above, but thanks anyway.

Comment by csgillespie — November 25, 2010 @ 2:21 pm

' src=

I wouldn’t mind if it wasn’t so much more costly to type <- ([hold shift] , [release shift] -) than =.

Comment by Oisín — October 14, 2011 @ 6:29 pm

' src=

It’s worth noting that you MUST use the = operator within reference classes when declaring each component. For example, MyClass <- setRefClass( "MyClass", methods = list( myFunction = function( … etc.

Comment by Sherlock — October 31, 2012 @ 6:02 pm

In your case, that would be (regular) argument names, which are always followed by a “=”.

Comment by Roman Luštrik — November 1, 2012 @ 9:04 am

That’s because setRefClass is a function, and so you need to use function-calling syntax within it. It’s the same principle as, for example, if you were calculating a variance you must use var(x, na.rm = TRUE) rather than var(x, na.rm <- TRUE).

Comment by richierocks — November 1, 2012 @ 9:05 am

' src=

may be because R can assign to function call, and have 2 direction of assignments. for instance, if data looks like

xs = c(16,23,42) ys = c(‘i’, ‘am’, ‘lost’)

assignment by equal operator might be ambiguous (for human) with this

names(xs) = ys

but it’s clearly obvious to see what happen with this

names(xs) ys

just some thought after learning R as 2nd language after Python.

Comment by เนยสด แรมหมด ติดบั๊ก (@neizod) — May 26, 2015 @ 4:16 pm

names(xs) <- ys

names(xs) -> ys

Comment by เนยสด แรมหมด ติดบั๊ก (@neizod) — May 26, 2015 @ 4:18 pm

' src=

The book on time series using R by Shumway and Stoffer also uses the “=” rather than the cumbersome (archaic, unnecessary) “<-".

Comment by Ravi — November 23, 2015 @ 9:47 am

' src=

While there are a couple of slight differences, you shouldn’t ever actually encounter a situation where the difference between ‘=’ and <- matters. If you are making code where the subtle, idiosyncratic weirdness matters, I suggest you have bigger problems. Using '=' is compatible with most other languages, there's really no practical reason to bog your code down with '<-' save to keeping kinds of people happy.

Comment by Benjamin Wiseman — August 12, 2016 @ 9:38 pm

' src=

Not only is <- harder to read, ambiguous in cases of x<-2 vs x < -2, and in conflict with general programming language convention, has anyone done some objective measurement of how much longer it takes to type? And remember, the assignment operator is the most commonly used operator, so you have to multiple the time wastage by a factor of hundreds, if not thousands, each and every day you program. Why would anyone waste a large chunk of their life just to indulge R's insistence on stylish distinctiveness?

Comment by Not Stupid — December 26, 2017 @ 7:41 am

' src=

Vast majority of my time is dedicated to thinking about code and processes and not typing. Saving on an already minute task yields… well, minute benefits.

Comment by Roman Luštrik — October 12, 2018 @ 12:57 pm

[…] From my perspective, this can make R code very obtuse and confusing to read (e.g. there are two assignment operators, <- and […]

Pingback by What is R? – Beer, Biology and Physics — May 3, 2018 @ 1:00 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply Cancel reply

Recent posts.

  • Speeding up package installation
  • UK R Courses
  • Security: the dangers of copying and pasting R code
  • Training courses: R, Stan and Scala
  • Input/output benchmarks
  • benchmarkme Update
  • List of R conferences and useR groups
  • R Courses at London, Leeds and Newcastle
  • R Courses at Newcastle
  • RStudio addins manager
  • RANDU: The case of the bad RNG
  • Shiny benchmarks
  • November 2017
  • January 2017
  • November 2016
  • August 2016
  • February 2016
  • December 2015
  • September 2011
  • August 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • Healthy Algorithms
  • eridanus.net
  • Xi'an's Og
  • Entries feed
  • Comments feed
  • WordPress.com

Create a free website or blog at WordPress.com.

' src=

  • Already have a WordPress.com account? Log in now.
  • Follow Following
  • Copy shortlink
  • Report this content
  • View post in Reader
  • Manage subscriptions
  • Collapse this bar


  1. Why do we use arrow as an assignment operator?

    r assignment arrow or equal

  2. R Programming Assignment Help & R Programming Project and Homework Help

    r assignment arrow or equal

  3. Why do we use arrow as an assignment operator?

    r assignment arrow or equal

  4. Assignment Operators in R

    r assignment arrow or equal

  5. Arrow Symbol Material Conditional LaTeX Mathematics, PNG, 1200x672px, Symbol, Black, Black And

    r assignment arrow or equal

  6. Why do we use arrow as an assignment operator?

    r assignment arrow or equal


  1. Chosen Elhew Arrow

  2. EYBM Career Reflective Video Submission Assignment 3

  3. My Arrow Video Pick-ups From July

  4. sta 404 assignment 1 solution fall 2023|sta404 assignment 1 solution fall 2023|sta404 assignment 1

  5. CS610p Assignment 1 Solution 2023

  6. Create List with Names but no Entries in R (Example)


  1. What Jeweler Makes a Gold Ring With a U and an Arrow Through It?

    The Uncas Manufacturing Company uses a U with an arrow through it as its hallmark, or jeweler’s mark, on its sterling and costume jewelry. The company changed its original jeweler’s mark and started using the symbol in the mid-1920s.

  2. The Ultimate Guide to Finding the Best Arrow Pest Control Near You

    If you’re dealing with a pest problem in your home or business, you want to find a reliable and effective pest control company that can quickly eliminate the issue. One option that many people consider is Arrow Pest Control.

  3. What Does the Arrow Through the Heart Mean?

    An arrow through the heart symbolizes feeling emotionally wounded, typically from romantic love. The arrow is that of Cupid, the god of erotic love in classical mythology. He is portrayed as a slender young man or a winged, chubby boy and c...

  4. assignment operator

    ... R", by Robert and Casella: "The assignment operator is = , not to be confused with == , which is the Boolean operator for equality. An older

  5. Assignment Operators in R (3 Examples)

    Generally speaking, there is a preference in the R programming community to use an arrow (i.e. <-) instead of an equal sign (i.e. =) for assignment. In my

  6. Why do we use arrow as an assignment operator?

    ... assignment was made like this 🙂. The main reason “equal assignment” was introduced is because other languages uses. = = as an assignment

  7. The difference between <- and = assignment in R

    ... equal sign '=', while in R, I was taught to do it through ... The arrows are respectively the leftwards assignment and the rightwards assignment.

  8. The difference between '=' and '<-' in R : r/rstats

    ... arrow-as-an-assignment-operator/. Upvote 4. Downvote Reply reply. Share ... Anecdotally, people with a statistics background prefer <- , as this

  9. Basic R 01

    Most of it uses equal operator ( = ) as the only one assignment operator. In R, the main and most used by R users is left-arrow operator ( <- ).

  10. Protect yourself from equals assignment!

    ... assignment arrow ( x <- 1 ) is better than equals ( x = 1 ) for assignment in R. So, unless you hate democracy, you should protect yourself

  11. Assignment Operators in R

    Equal or “arrow” as an Assignment Operator? In R, both the equal and arrow symbols work to assign values. Therefore, the following

  12. Use = or <- for assignment?

    ... R users: should you use = (equals) or <- (back arrow) for assignments? In R, both of the following statements have the effect of assigning

  13. Assignment operators in R: '=' vs. '<-'

    ... R uses <- for assignment, as referenced here: http://blog.revolutionanalytics.com/2008/12/use-equals-or-arrow-for-assignment.html · Reply.

  14. Why is '<-' assignment operator used in R rather than ...

    Originally Answered: What is the point of the '<-' assignment arrow in R? R uses the equal sign for assigning the arguments in functions.