title: Overlap join with start and end positions
body: <p>Consider the following <code>data.table</code>s. The first defines a set of regions with start and end positions for each group 'x':</p>
  
  <pre><code>library(data.table)
  
  d1 &lt;- data.table(x = letters[1:5], start = c(1,5,19,30, 7), end = c(3,11,22,39,25))
  setkey(d1, x, start)
  
  #    x start end
  # 1: a     1   3
  # 2: b     5  11
  # 3: c    19  22
  # 4: d    30  39
  # 5: e     7  25
  </code></pre>
  
  <p>The second data set has the same grouping variable 'x', and positions 'pos' within each group:</p>
  
  <pre><code>d2 &lt;- data.table(x = letters[c(1,1,2,2,3:5)], pos = c(2,3,3,12,20,52,10))
  setkey(d2, x, pos)
  
  #    x pos
  # 1: a   2
  # 2: a   3
  # 3: b   3
  # 4: b  12
  # 5: c  20
  # 6: d  52
  # 7: e  10
  </code></pre>
  
  <p>Ultimately I'd like to extract the rows in 'd2' where 'pos' falls within the range defined by 'start' and 'end', within each group <code>x</code>. The desired result is</p>
  
  <pre><code>#    x pos start  end
  # 1: a   2     1    3
  # 2: a   3     1    3
  # 3: c  20    19   22
  # 4: e  10     7   25
  </code></pre>
  
  <p>The start/end positions for any group <code>x</code> will never overlap but there may be gaps of values not in any region.</p>
  
  <p>Now, I believe I should be using a rolling join. From what i can tell, I cannot use the "end" column in the join.</p>
  
  <p>I've tried</p>
  
  <pre><code>d1[d2, roll = TRUE, nomatch = 0, mult = "all"][start &lt;= end]
  </code></pre>
  
  <p>and got </p>
  
  <pre><code>#    x start end
  # 1: a     2   3
  # 2: a     3   3
  # 3: c    20  22
  # 4: e    10  25
  </code></pre>
  
  <p>which is the right set of rows I want; However "pos" has become "start" and the original "start" has been lost. Is there a way to preserve all the columns with the roll join so i could report "start", "pos", "end" as desired?</p>