The tm
package extends c
so that, if given a set of PlainTextDocument
s it automatically creates a Corpus
. Unfortunately,
Here's another method that worked for my list of lists.
df <- as.data.frame(do.call(rbind, lapply(foolist, as.data.frame)))
I expect that unlist(foolist)
will help you. It has an option recursive
which is TRUE
by default.
So unlist(foolist, recursive = FALSE)
will return the list of the documents, and then you can combine them by:
do.call(c, unlist(foolist, recursive=FALSE))
do.call
just applies the function c
to the elements of the obtained list
Here's a more general solution for when lists are nested multiple times and the amount of nesting differs between elements of the lists:
flattenlist <- function(x){
morelists <- sapply(x, function(xprime) class(xprime)[1]=="list")
out <- c(x[!morelists], unlist(x[morelists], recursive=FALSE))
if(sum(morelists)){
Recall(out)
}else{
return(out)
}
}