title: Exceptions to sep = " " when reading table into R? Dealing with whitespace within fields
body: <p>I need to import a table into R that is separated by spaces. Unfortunately, within some of the fields, there are spaces which cause R to separate into a new row. Is there any way of making those fields 'stick together'? </p>
  
  <p>For example, the table looks like this:</p>
  
  <pre><code>V1    V2    V3    V4
  Text  More  0.11  (a)kdfs hdfa ag$
  Text  More  1.12  a
  Text  More  0.21  v
  Text  More  1222  (a)sdfs sdfa-&gt;g
  Text  More  1232  (a)sdfs sdfa-&gt;g
  </code></pre>
  
  <p>But gets turned into this when R reads it (using <code>read.delim</code>)</p>
  
  <pre><code>V1    V2    V3    V4
  Text  More  0.11  (a)kdfs 
  hdfa  ag$
  Text  More  1.12  a
  Text  More  0.21  v
  Text  More  1222  (a)sdfs 
  sdfa-&gt;g
  Text  More  1232  (a)sdfs 
  sdfa-&gt;g
  </code></pre>
  
  <p>Those fields all have weird characters that aren't all shared with the other columns/rows. However, as seen, the spaces aren't flanked by the same characters. </p>
  
  <p>In the original file, the rows are separated properly. Is there a way to do any of the following?</p>
  
  <ol>
  <li>Stop separating by spaces after the fourth column is created</li>
  <li>Have fields starting/ending with certain characters be stuck together as a string/add a non-space character where the spaces are</li>
  <li>Generically, allow exceptions to <code>sep</code></li>
  </ol>
  
  <p>Quite new to R so sorry if this is very naive. Here is what my script looks like up to then:</p>
  
  <pre><code>strs &lt;- readLines("file")
  dat &lt;- read.delim(text = strs, 
              skip = 17, 
              col.names = c("V1", "V2", "V3", "V4"),
              sep = " ", header = F) 
  </code></pre>
  
  <p>Is there anything I can add to either <code>read.delim</code> or <code>readLines</code> or in between those to fix this problem? As there is fluff that needs to be cut out (hence the <code>skip</code>) I can't use <code>read.table</code> (correct me if I'm wrong). </p>
  
  <p>Some of the characters around the spaces are shared, so I would be willing to use a more tedious method to put other characters in place of the spaces in between e.g. 's' and 's'. Would that be possible with <code>gsub</code> if there isn't an easier method?</p>
  
  <p>Thanks so much! </p>
  
  <p>EDIT: Flash of insight, would it be possible to make the fourth column a new table (that's of course not separated by spaces), then replace all spaces in that table with something else? How would I go about 'breaking off' the fourth column/columns after the third column?</p>