title: Checking if string is in uppercase in R
body: <p>Is there simpler method to match regex pattern in its entirety? For example, to check if given string is uppercase the following 2 methods but seem too complex. Checking <strong>stringr</strong> I found no indication for simpler solution either.</p>
  
  <p><strong>Method 1:</strong></p>
  
  <pre><code>isUpperMethod1 &lt;- function(s) {
    return (all(grepl("[[:upper:]]", strsplit(s, "")[[1]])))
  }
  </code></pre>
  
  <p><strong>Method 2:</strong></p>
  
  <pre><code>isUpperMethod2 &lt;- function(s) {
    m = regexpr("[[:upper:]]+", s)
    return (regmatches(s, m) == s)
  }
  </code></pre>
  
  <p>I intentionally omit handling of empty, NA, NULL strings to avoid bloated code.</p>
  
  <p><strong>The uppercase pattern can be generalized to arbitrarily regex pattern (or character set).</strong></p>
  
  <p>I see no problems with both solutions above except that they seem excessively complex for the problem solved.</p>