title: How to test Rcpp::CharacterVector elements for equality?
body: <p>I am trying to write some simple Rcpp code examples.  This is remarkably easy with the <code>Rcpp</code> and <code>inline</code> packages.</p>
  
  <p>But I am stumped on how to test whether two character elements for equality.  The following example compares the first elements of two character vectors.  But I can't get it to compile.</p>
  
  <p>What is the trick?</p>
  
  <pre><code>library(Rcpp)
  library(inline)
  
  cCode &lt;- '
      Rcpp::CharacterVector cx(x);
      Rcpp::CharacterVector cy(y);
      Rcpp::LogicalVector r(1);
      r[0] = (cx[0] == cy[0]);
      return(r);
      '
  
  cCharCompare &lt;- cxxfunction(signature(x="character", y="character"), 
                              plugin="Rcpp", body=cCode)
  cCharCompare("a", "b")
  </code></pre>
  
  <p>--</p>
  
  <p>The comparison using <code>==</code> works perfectly fine if one of the two elements is a constant.  The following code compiles and gives expected results:</p>
  
  <pre><code>cCode &lt;- '
      Rcpp::CharacterVector cx(x);
      Rcpp::LogicalVector r(1);
      r[0] = (cx[0] == "a");
      return(r);
      '
  
  cCharCompareA &lt;- cxxfunction(signature(x="character"), plugin="Rcpp", body=cCode)
  
  cCharCompareA("a")
  [1] TRUE
  
  cCharCompareA("b")
  [1] FALSE
  </code></pre>