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

2009-10-14 Thread Dieter Menne
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

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

2009-10-14 Thread Dieter Menne
kenhorvath wrote: Dieter Menne wrote: library(tm) filenames = list.files(path=.,pattern=\\.txt) docs = for (filename in filenames){ docs = c(docs,paste(readLines(file(filename)),collapse=\n)) } docs ## continue as in example vs = VectorSource(docs) If in any way

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

2009-10-14 Thread kenhorvath
Richard Liu wrote: 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. Yes, that is what 'collapse' should do! If you read text using

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

2009-10-14 Thread kenhorvath
Dieter Menne wrote: While I agree that the appending could be more efficiently be done by a list as an intermediate, the docs = c(doc, ljljljl) construct is not recursive, even if not efficient. Yes, of course, that was hastily written, sorry ... but from my experience list

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

2009-10-13 Thread Dieter Menne
Richard Liu wrote: I'm new to R. I'm working with the text mining package tm. I have several plain text documents in a directory, and I would like to read all the files with extension .txt in that directory into a vector, one text document per vector element. That is, v[1] would be the

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

2009-10-13 Thread Richard Liu
I'm new to R. I'm working with the text mining package tm. I have several plain text documents in a directory, and I would like to read all the files with extension .txt in that directory into a vector, one text document per vector element. That is, v[1] would be the first document, v[2] the

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

2009-10-13 Thread Paul Hiemstra
Richard Liu wrote: I'm new to R. I'm working with the text mining package tm. I have several plain text documents in a directory, and I would like to read all the files with extension .txt in that directory into a vector, one text document per vector element. That is, v[1] would be the first

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

2009-10-13 Thread kenhorvath
Paul Hiemstra wrote: file_list = list.files(/where/are/the/files) obj_list = lapply(file_list, FUN = yourfunction) yourfunction is probably either read.table or some read function from the tm package. So obj_list will become a list of either data.frame's or tm objects. The

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

2009-10-13 Thread Richard Liu
kenhorvath wrote: Paul Hiemstra wrote: file_list = list.files(/where/are/the/files) obj_list = lapply(file_list, FUN = yourfunction) yourfunction is probably either read.table or some read function from the tm package. So obj_list will become a list of either data.frame's or