title: Sub-setting data table using & and grepl
body: <p>I've got a data set with column names like:</p>
  
  <pre><code>names(d)
   [1] "Code"        "LX(RI)"      "LX(VO)"      "LX(MV)"      "LX(WC189)" "LX(WC035)"
   [7] "NX(RI)"      "NX(VO)"      "NX(MV)"      "NX(WC189)"   "NX(WC035)" "AX(RI)"     
  [13] "AX(VO)"      "AX(MV)"      "AX(WC189)"   "AX(WC035)"   "SX3I(RI)"  "SXI(VO)"    
  [19] "SXI(MV)"     "TX(RI)"      "TX(VO)"      "TX(MV)"      "TX(WC189)" "TX(WC035)"
  </code></pre>
  
  <p>Each column has several thousand rows associated with it. What I want to do is use <code>grepl</code> to subset the data table's columns based on those ending with RI AND retaining the Code column.</p>
  
  <p>Currently I've worked out how to subset all the RI columns into a new data.table, but I can't figure out how to include the Code column.</p>
  
  <p>I have currently:</p>
  
  <pre><code>RI &lt;- d[, grepl("\\(RI", names(d)), with = FALSE]
  </code></pre>
  
  <p>Which gives me what I want:</p>
  
  <pre><code>names(RI)
  [1] "LX(RI)" "NX(RI)" "AX(RI)" "SX3I(RI)" "TX(RI)"
  </code></pre>
  
  <p>I've been trying (note that I have included &amp;Code):</p>
  
  <pre><code>RI &lt;- d[, grepl("\\(RI&amp;Code", names(d)), with = FALSE]
  </code></pre>
  
  <p>Which I want to return a data table with the following columns:</p>
  
  <pre><code>[1] "LX(RI)" "NX(RI)" "AX(RI)" "SX3I(RI)" "TX(RI)" "Code"
  </code></pre>
  
  <p>The above is my desired output. The code however does nothing and returns an empty data table.</p>
  
  <p>A couple of questions:</p>
  
  <ul>
  <li>Can I use &amp; in grepl? If so, is my example using &amp; incorrect?</li>
  <li>If not, are there any suggestions on how to subset for both RI columns and the Code?</li>
  </ul>