为环境中的名称赋值和设置变量的环境有什么区别?我无法从文档中弄清楚。
例如:
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