How to flatten a list to a list without coercion?
Interesting non-trivial problem! MAJOR UPDATE With all that’s happened, I’ve rewrote the answer and removed some dead ends. I also timed the various solutions on different cases. Here’s the first, rather simple but slow, solution: flatten1 <- function(x) { y <- list() rapply(x, function(x) y <<- c(y,x)) y } rapply lets you traverse a list … Read more