title: Get characters before first space
body: <p>I am looking for a grep way to obtain the characters in a string prior to the first space. </p>
  
  <p>I have hacked the following function, as i could not figure out how to do it using the <code>grep</code> type commands in <code>R</code>. </p>
  
  <p>Could someone help with the <code>grep</code> solution - if there is one ... </p>
  
  <pre><code>beforeSpace &lt;- function(inWords) {
      vapply(inWords, function(L) strsplit(L, "[[:space:]]")[[1]][1], FUN.VALUE = 'character')
  }
  words &lt;- c("the quick", "brown dogs were", "lazier than quick foxes")
  beforeSpace(words)
  
  R&gt;          the quick         brown dogs were lazier than quick foxes 
                "the"                 "brown"                "lazier" 
  </code></pre>
  
  <p>And do let me know if there's a better way than <code>grep</code> (or my function, <code>beforeSpace</code>) to do this. </p>