I am trying to explain the scope and debugging for a presentation on R. I read the help file for <<-and saw how it says this:
The <<and →> operators are usually used only in functions and cause a search in the parent environments for the existing definition of the assigned variable. If such a variable is found (and its binding is not blocked), then its value is overridden, otherwise the assignment is performed in the global environment.
But I don’t think it fully describes what he is doing <<-. Here is the function:
do.func <- function() {
x <- 1
{
x<<-0
}
print(x)
}
do.func()
x
produces this conclusion:
> do.func()
[1] 1
> x
[1] 0
It seems to be <<-doing right in the global environment. Is it correct?
Adamo