But occasionally it isn't. For example in functions within functions, or in an error function in
Strictly speaking, does
<<- assign to the global environment, or simply to the parent environment?
Try it out:
env = new.env() env2 = new.env(parent = env) local(x <<- 42, env2) ls(env) # character(0) ls() #  "env" "env2" "x"
env$x = 1 local(x <<- 2, env2) env$x #  2
<<- does walk up the entire chain of parent environments until it finds an existing object of the given name, and replaces that. However, if it doesn’t find any such object, it creates a new object in
(The documentation states much the same. But in a case such as this nothing beats experimenting to gain a better understanding.)