Вопрос

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top