Reputation: 1610
Suppose that I wanted to create a new environment with members a=5
, b=6
, and c=7
. This is the best way that I know:
e<-new.env()
e$a<-5
e$b<-6
e$c<-7
Compared to the equivalent syntax for lists, which would just be e<-list(a=5,b=6,c=7)
, this is a pain. I know that the Tidyverse has a better way of doing this, but what about base R? Is there a different syntax for creating environments and adding elements?
Upvotes: 1
Views: 38
Reputation: 887911
If we create a named list
, an option to create objects would be list2env
. The envir
can be .GlobalEnv
(creates objects on the global environment) or a custom environment (e
)
list2env(list(a = 5, b = 6, c = 7), envir = e)
Upvotes: 1