title: How do I count the number of words in a text (string)?
body: <p>I have this string vector (for example):</p>
  
  <pre><code>str &lt;- c("this is a string current trey",
      "feather rtttt",
      "tusla",
      "laq")
  </code></pre>
  
  <p>To count the number of words in this vector I used this (as given here <a href="https://stackoverflow.com/questions/8920145/count-the-number-of-words-in-a-string-in-r">Count the number of words in a string in R?</a>, which is a possible duplicate but with another issue)</p>
  
  <pre><code>No_words &lt;- sapply(gregexpr("\\W+", str), length) + 1
  </code></pre>
  
  <p>but it returns </p>
  
  <pre><code>6 2 2 2
  </code></pre>
  
  <p>String has only 1 element in last two places (i.e. <code>"tusla"</code> and <code>"laq"</code>)</p>
  
  <p>so it should return </p>
  
  <pre><code>6 2 1 1
  </code></pre>
  
  <p>How do I get around this problem?  </p>