[R] How to read contents of a text file into a single string?

Erik Iverson eriki at ccbr.umn.edu
Wed Apr 28 17:08:03 CEST 2010



Dimitri Shvorob wrote:
> ... Both readLines() and scan() produce a number_of_lines x 1 vector; trying
> paste(s, collapse = NULL) leaves it unaffected. How can I concatenate vector
> elements (lines) into a single string? 
> Thank you.

Read ?paste, specifically:

      If a value is specified for ‘collapse’, the values in the result
      are then concatenated into a single string, with the elements
      being separated by the value of ‘collapse’.


You need to specify, say,  collapse = " ".



More information about the R-help mailing list