I have 257 .txt files, each has a bunch of Q+A transcripts. I want to extract the text from each one into a single vector in R. Most of the related questions involve reading in multiple files into a dataframe or table, I don't want either of those, just a huge chunk of text.
I did successfully get all the files in:
QA_all <- choose.files()
But beyond that I'm stumped. A solution mentioned here: Import multiple text files in R and assign them names from a predetermined list
seemed to approximate what I want, but it's a list of some kind. I was able to extract the text items from the list into a vector and then flatten it and remove lines:
#extract text from files and put in a vector
data_list = lapply(QA_all, function(file) scan(file, what = "character"))
text <- c(data_list[1:257])
flat.list <- unlist(text, recursive = TRUE, use.names = TRUE)
#remove lines
QA.vector <- paste(flat.list, collapse=" ")
but I wonder If I can this directly without having to create a list with lapply(). I want to know if there's a more direct way to extract text from several files and put them into onto contiguous unit of text in R.