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

Dieter Menne dieter.menne at menne-biomed.de
Wed Oct 14 10:15:51 CEST 2009




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 possible I would recommend to do the whole procedure via
> lists, not recursively.
> 
> Ken
> 

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.

Dieer


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




More information about the R-help mailing list