title: Equivalent of substr for raw vectors
body: <p>Is there an equivalent of <code>substring</code> for <code>raw</code> vectors in <code>R</code>?</p>
  
  <p>Say that I have a large binary raw vector <code>x</code>, e.g. as a result from reading a file using <code>readBin</code>. Now I used <code>grepRaw</code> to find the index of some fragment inside the raw vector that I would like to access. A toy example:</p>
  
  <pre><code>x &lt;- charToRaw("foobar");
  n &lt;- 2;
  m &lt;- 5;
  </code></pre>
  
  <p>Now I would like to extract the "substring" from positions 2 and 5. A native way to do so is:</p>
  
  <pre><code>x[n:m]
  </code></pre>
  
  <p>However, this scales poorly for large fragments, because R first creates a large vector <code>n:m</code> and then iterates over this vector to extract the elements from <code>x</code> at these indices, one by one. Is there a more native method to extract a part of a <code>raw</code> vector, similar to <code>substr</code> for character vectors? I don't think I can use <code>rawToChar</code> because the files might contain non-text binary data.</p>