[R] How to read plain text documents into a vector?

Dieter Menne dieter.menne at menne-biomed.de
Wed Oct 14 08:37:07 CEST 2009

Richard Liu wrote:
>  There are actually two vignettes.  Both have examples of a vector of
> characters being made into a tm corpus, but neither shows how to read
> documents on the file system into the vectors.  I tried the other two
> suggestions, but paste seemed not to "glue" the separate lines together
> into one character string.  Perhaps I missed something (collapse?). 
> Perhaps I'll have another look.

I admit, an example to read in external data is missing. Maybe inform the
Try if this works; I have not use the special functions in tm, so there
might be another problem, but readPlain looks like a good place to continue


filenames = list.files(path=".",pattern="\\.txt")
docs = ""
for (filename in filenames){
  docs = c(docs,paste(readLines(file(filename)),collapse="\n"))
## continue as in example
vs = VectorSource(docs)

View this message in context: http://www.nabble.com/How-to-read-plain-text-documents-into-a-vector--tp25867792p25886104.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list