If you don’t need names, and your list is one level of depth, then if you can win
.Internal(unlist(your_list, FALSE, FALSE))
I will vote for everything you do on SO over the next 1 year !!!
[Update: if you need unstudied names, and the list is not recursive, here is a version that improves the list more than 100 times
myunlist <- function(l){ names <- names(l) vec <- unlist(l, F, F) reps <- unlist(lapply(l, length), F, F) names(vec) <- rep(names, reps) vec } myunlist(list(a=1:3, b=2)) aaab 1 2 3 2 > tl <- list(a = 1:20000, b = 1:5000, c = 2:30) > system.time(for(i in 1:200) unlist(tl)) user system elapsed 22.97 0.00 23.00 > system.time(for(i in 1:200) myunlist(tl)) user system elapsed 0.2 0.0 0.2 > system.time(for(i in 1:200) unlist(tl, F, F)) user system elapsed 0.02 0.00 0.02
]
[Update 2: Answer the Nr3 call from Richie Cotton.
bigList3 <- replicate(500, rnorm(1e3), simplify = F) unlist_vit <- function(l){ names(l) <- NULL do.call(c, l) } library(rbenchmark) benchmark(unlist = unlist(bigList3, FALSE, FALSE), rjc = unlist_rjc(bigList3), vit = unlist_vit(bigList3), order = "elapsed", replications = 100, columns = c("test", "relative", "elapsed") ) test relative elapsed 1 unlist 1.0000 2.06 3 vit 1.4369 2.96 2 rjc 3.5146 7.24
]
PS: I suppose the “big fish” is the one that has more reputation than you. So I'm very small here :).