Strictly speaking does the scoping assignment <<- assign to the parent environment or global environment?
问题 Often the parent environment is the global environment. But occasionally it isn't. For example in functions within functions, or in an error function in tryCatch() . Strictly speaking, does <<- assign to the global environment, or simply to the parent environment? 回答1: Try it out: env = new.env() env2 = new.env(parent = env) local(x <<- 42, env2) ls(env) # character(0) ls() # [1] "env" "env2" "x" But: env$x = 1 local(x <<- 2, env2) env$x # [1] 2 … so <<- does walk up the entire chain of