title: data.table: Error during wrapup: Internal error: NA exist in 'rows' passed to C assign
body: <p>Well, this worked fine for me yesterday in a function I have.  Today I am having the following problem with this data.table.  I cant figure out what I did wrong or changed to get this behavior:</p>
  
  <pre><code>dtable
     TIF VENUE duration TYPE1 TYPE2 TYPE3 TYPE4 index order_type
  1: DAY    NA  1.3e+07    NA   M:0    NA    NA     2         NA
  2: DAY    NA  2.0e+06    NA   M:0    NA    NA     4         NA
  3: DAY    NA  8.9e+07    NA   M:0    NA    NA     6         NA
  4: IOC    NA  0.0e+00    NA    NA    NA    NA     1         NA
  5: IOC    NA  0.0e+00    NA    NA    NA    NA     3         NA
  6: IOC    NA  0.0e+00    NA    NA    NA    NA     5         NA
  
  Classes:
          TIF       VENUE    duration       TYPE1       TYPE2       TYPE3       TYPE4    index    order_type
     "factor"    "factor"   "numeric"    "factor"    "factor"    "factor"    "factor"   "integer" "character"
  
  
  
  
  
  cn = "TYPE2"
  pattern = "M:?\\n*\\.?\\n*"
  tif = "DAY"
  &gt; type
  [1] mid-peg
  Levels: ERROR? GTC? far-peg far-peg ping limit limit ping mid-peg mid-peg ping near-peg near-peg ping
  
  index = grep(pattern, dtable[tif][, get(cn)])
  index
  &gt; [1] 1 2 3
  </code></pre>
  
  <p>This fails:</p>
  
  <pre><code>dtable[tif][index][,"order_type"] = type              
  **Error during wrapup: Internal error: NA exist in 'rows' passed to C assign**
  </code></pre>
  
  <p>This works:</p>
  
  <pre><code>dtable[tif][grep(pattern, dtable[tif][, get(cn)])][,"order_type"] = type
  &gt; dtable
     TIF VENUE duration TYPE1 TYPE2 TYPE3 TYPE4 index order_type
  1: DAY    NA  1.3e+07    NA   M:0    NA    NA     2    mid-peg
  2: DAY    NA  2.0e+06    NA   M:0    NA    NA     4    mid-peg
  3: DAY    NA  8.9e+07    NA   M:0    NA    NA     6    mid-peg
  4: IOC    NA  0.0e+00    NA    NA    NA    NA     1         NA
  5: IOC    NA  0.0e+00    NA    NA    NA    NA     3         NA
  6: IOC    NA  0.0e+00    NA    NA    NA    NA     5         NA
  </code></pre>
  
  <p>What am I screwing up?</p>
  
  <p>I thought my R session was corrupt so I brought up a new one and it failed as well.</p>
  
  <p>Thank you for your time.</p>
  
  <p>(Sorry folks, first time using this site so I shouldn't have put the following in the comments section)
  For the suggestion to use ....[,order_type :- type ]</p>
  
  <p>Here it is: same dtable as above. I left the exmaple in memory with the same parms above. </p>
  
  <pre><code>&gt;dtable[tif][grep(pattern, dtable[tif][, get(cn)])][,order_type] 
  [1] NA NA NA 
  
  &gt;dtable[tif][grep(pattern, dtable[tif][, get(cn)])][,order_type := type ] 
  &gt;dtable[tif][grep(pattern, dtable[tif][, get(cn)])][,order_type] 
  [1] NA NA NA 
  
  &gt; type [1] mid-peg. 
  [1] mid-peg
  Levels: ERROR? GTC? far-peg far-peg ping limit limit ping mid-peg mid-peg ping near-peg near-peg ping
  </code></pre>
  
  <p>Now doing this after, it works:</p>
  
  <pre><code>&gt; dtable[tif][grep(pattern, dtable[tif][, get(cn)])][,"order_type"] = type
  &gt; dtable[tif][grep(pattern, dtable[tif][, get(cn)])][,order_type] 
  [1] "mid-peg" "mid-peg" "mid-peg"
  </code></pre>
  
  <p>I apologize if this looks odd.  When I first started this whole thing, I did originally try:</p>
  
  <pre><code>&gt;index = grep(pattern, dtable[tif][, get(cn)])
  &gt;dtable[tif][index][,order_type := type ]
  </code></pre>
  
  <p>This didnt work.  I did seem (or thought) I had the following working 2 nights ago:</p>
  
  <pre><code>&gt;dtable[tif][index][,"order_type"] = type
  </code></pre>
  
  <p>but now I get the error:
   Internal error: NA exist in 'rows' passed to C assign</p>
  
  <p>After mucking with this for a while, I was surprised that replacing [index] with 
  [grep(pattern, dtable[tif][, get(cn)])] worked as it should be the same thing.  So that left me scratching my head back to the original problem way above.</p>
  
  <p>I just started using data.table about a month ago.  It was great advantages and a major boost for me but there are a few odd quirks I have come across, like this one.  So I finally thought I should post this out there to see what I am doing wrong or if I am using data.table in a way not intended.  </p>
  
  <p>Totally forgot to mention, I am using R3.0
  Thank you all.</p>