title: How to assign output of cat to an object?
body: <p>How would it be possible in the example below to skip the step of writing to file "test.txt", i.e. assign the cat-result to an object, and still achieve the same end result?</p>
  
  <p>I thought I'd include the full example to give background to my problem.</p>
  
  <pre><code>test &lt;- c("V 1", "x", "1 2 3", "y", "3 5 8", "V 2", "x", "y", "V 3", "y", "7 2 1", "V 4", "x", "9 3 7", "y")
  
  # Write selection to file
  cat(test, "\n", file="test.txt")
  test2 &lt;- readLines("test.txt")
  test3 &lt;- strsplit(test2, "V ")[[1]][-1]
  
  # Find results
  x &lt;- gsub("([0-9]) (?:x )?([0-9] [0-9] [0-9])?.*", "\\1 \\2 ", test3, perl = TRUE)
  y &lt;- gsub("([0-9]).* y ?([0-9] [0-9] [0-9])?.*", "\\1 \\2 ", test3, perl = TRUE)
  
  # Eliminate tests with no results
  x1 &lt;- x[regexpr("[0-9] ([^0-9]).*", x) == -1]
  y1 &lt;- y[regexpr("[0-9] ([^0-9]).*", y) == -1]
  
  # Dataframe of results
  xdf1 &lt;- read.table(textConnection(x1), col.names=c("id","x1","x2","x3"))
  ydf1 &lt;- read.table(textConnection(y1), col.names=c("id","y1","y2","y3"))
  closeAllConnections()
  
  # Dataframe of tests with no results
  x2 &lt;- x[regexpr("[0-9] ([^0-9]).*", x) == 1]
  y2 &lt;- y[regexpr("[0-9] ([^0-9]).*", y) == 1]
  
  df1 &lt;- as.integer(x2[x2 == y2])
  df1 &lt;- data.frame(id = df1)
  
  # Merge dataframes
  results &lt;- merge(xdf1, ydf1, all = TRUE)
  results &lt;- merge(results, df1, all = TRUE)
  results
  </code></pre>
  
  <p>Results in:</p>
  
  <pre><code>  id x1 x2 x3 y1 y2 y3
  1  1  1  2  3  3  5  8
  2  2 NA NA NA NA NA NA
  3  3 NA NA NA  7  2  1
  4  4  9  3  7 NA NA NA
  </code></pre>