What are the differences in the assignment operators <-
and <<-
in R?
And when should <<-
be used?
<-
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With