Sự khác nhau giữa việc gán giá trị cho tên trong môi trường và thiết lập môi trường của một biến là gì? Tôi không thể tìm ra từ tài liệu.Sự khác biệt giữa gán (..., envir = ...) và môi trường (...) =
ví dụ:
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
Cảm ơn câu trả lời siêu rõ ràng! – SFun28