有没有办法在调用 new.env() 时将“indian”、“pizza”和“ramen”这三个名称初始化为参数?
eats <- new.env(
indian = "8elements",
pizza = "blue line",
ramen = "orenchi")
这将是一个替代方案:
eats <- new.env()
eats$indian = "8elements"
eats$pizza = "blue line"
eats$ramen = "orenchi"
最佳答案
以下是一些替代方案:
1) 创建列表并将其转换为环境
eats <- list2env(list(
indian = "8elements",
pizza = "blue line",
ramen = "orenchi"))
2) 另一种可能性是像这样使用
local
:eats <- local({
indian = "8elements"
pizza = "blue line"
ramen = "orenchi"
environment()
})
3) proto 包创建了 proto 对象,它们实际上是环境,因此:
library(proto)
eats <- proto(
indian = "8elements",
pizza = "blue line",
ramen = "orenchi")
关于R:将环境名称设置为 new.env() 的参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46779718/