It would be very helpful to me to be able to create an R list object without having to specify the names of each element. For example:
a1 <- 1
a2 <- 20
a3 <- 1:20
b <- list(a1,a2,a3, inherit.name=TRUE)
> b
[[a1]]
[1] 1
[[a2]]
[1] 20
[[a3]]
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
This would be ideal. Any suggestions?
A random idea:
(The idea is stolen from the code in
data.frame
.)Another idea ,
Coincidentally, I just wrote this function. It looks a lot like @joran's solution, but it tries not to stomp on already-named arguments.
Copied from comments: if you want something from a CRAN package, you can use
Hmisc::llist
:The only apparent difference is that the individual vectors also have names in this case.
The
tidyverse
packagetibble
has a function that can do this as well. Try outtibble::lst