Why does the following not work? That is, why calling "$ <-" in the environment has a visible effect outside the function?
myAssign <- function(env, name, value) {
"$<-"(env, name, value)
}
e <- new.env()
myAssign(e, "x", 1)
e$x # NULL
And
myAssign(e, "x", 1)$x # NULL
If we do this at the top level:
"$<-"(e, "x", 1)
e$x # 1
Thank!
source
share