jennybc · GitHub

Opening at @hadley's suggestion on twitter. Relevant to a triplicated question on stackoverflow. Overlaps with the store() proposal by @lionel- over in purrr.

If list components could get named at creation time, that would be handy.

thing_one <- head(iris, 3)
thing_two <- head(iris, 3)
## our current options
thing_list <- list(thing_one = thing_one, thing_two = thing_two)
thing_list <- mget(c("thing_one", "thing_two"))
str(thing_list, max.level = 1)
## List of 2
##  $ thing_one:'data.frame':   3 obs. of  5 variables:
##  $ thing_two:'data.frame':   3 obs. of  5 variables:
## names can by so handy in downstream operations, e.g.
plyr::ldply(thing_list, .id = "came_from")
##   came_from Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1 thing_one          5.1         3.5          1.4         0.2  setosa
## 2 thing_one          4.9         3.0          1.4         0.2  setosa
## 3 thing_one          4.7         3.2          1.3         0.2  setosa
## 4 thing_two          5.1         3.5          1.4         0.2  setosa
## 5 thing_two          4.9         3.0          1.4         0.2  setosa
## 6 thing_two          4.7         3.2          1.3         0.2  setosa
## wishful thinking
#thing_list <- list(thing_one, thing_two)
#thing_list <- magical_list_fxn("^thing_")

Read the original on github.com ↗