Qual è la differenza tra l'assegnazione di un valore a un nome in un ambiente e l'impostazione dell'ambiente di una variabile? Non riuscivo a capirlo dalla documentazione.Differenza tra assign (..., envir = ...) e environment (...) =
ad esempio:
MyTestFunc = function(x)
{
myVal = "abcde"
# what is this doing? why is myVal not in the global environment after
# this call? I see it adds an environment attribute to the variable,
# but what good is that?
environment(myVal) = globalenv()
assign("myVal" , myVal , envir = globalenv())
# this seems to copy graphics:::rect to the current environment which seems
# to contradict the behavior of environment(myVal) above
environment(rect) = environment()
# this seems to do the same thing
assign("rect" , rect , envir = globalenv())
}
# this prints out rect, but shows <environment: namespace: graphics>!
rect
Grazie per la risposta super chiara! – SFun28