5

What are the differences in the assignment operators <- and <<- in R?

And when should <<- be used?

Thomas
  • 42,067
  • 12
  • 102
  • 136
csiu
  • 3,019
  • 2
  • 23
  • 26

1 Answers1

7

<- assigns an object to the environment in which it is evaluated (local scope). <<- assigns an object to the next highest environment that the name is found in or the global namespace if no name is found. See the documentation here.

<<- is usually only used in functions, but be careful. <<- can be much harder to debug because it is harder to trace the evaluation of the assignment. It is better to write functions with return statements instead.

Hadley Wickham has a good explination in his Advanced R Programming Book.

Christopher Louden
  • 7,317
  • 2
  • 24
  • 29