<div dir="ltr"><div style>This is regarding: </div><a href="http://stackoverflow.com/questions/17508127/na-in-i-expression-of-data-table-possible-bug">http://stackoverflow.com/questions/17508127/na-in-i-expression-of-data-table-possible-bug</a><div>
<br></div><div><pre class="" style="margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:13.333333969116211px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;line-height:16.666667938232422px">
<code style="margin:0px;padding:0px;border:0px;font-size:13.333333969116211px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif"><span class="" style="color:rgb(0,0,0);margin:0px;padding:0px;border:0px;font-size:13.333333969116211px;vertical-align:baseline;background-color:transparent">x </span><span class="" style="color:rgb(0,0,0);margin:0px;padding:0px;border:0px;font-size:13.333333969116211px;vertical-align:baseline;background-color:transparent">=</span><span class="" style="color:rgb(0,0,0);margin:0px;padding:0px;border:0px;font-size:13.333333969116211px;vertical-align:baseline;background-color:transparent"> data</span><span class="" style="color:rgb(0,0,0);margin:0px;padding:0px;border:0px;font-size:13.333333969116211px;vertical-align:baseline;background-color:transparent">.</span><span class="" style="color:rgb(0,0,0);margin:0px;padding:0px;border:0px;font-size:13.333333969116211px;vertical-align:baseline;background-color:transparent">table</span><span class="" style="color:rgb(0,0,0);margin:0px;padding:0px;border:0px;font-size:13.333333969116211px;vertical-align:baseline;background-color:transparent">(</span><span class="" style="color:rgb(0,0,0);margin:0px;padding:0px;border:0px;font-size:13.333333969116211px;vertical-align:baseline;background-color:transparent">a</span><span class="" style="color:rgb(0,0,0);margin:0px;padding:0px;border:0px;font-size:13.333333969116211px;vertical-align:baseline;background-color:transparent">=</span><span class="" style="color:rgb(0,0,0);margin:0px;padding:0px;border:0px;font-size:13.333333969116211px;vertical-align:baseline;background-color:transparent">c</span><span class="" style="color:rgb(0,0,0);margin:0px;padding:0px;border:0px;font-size:13.333333969116211px;vertical-align:baseline;background-color:transparent">(</span><span class="" style="color:rgb(0,0,0);margin:0px;padding:0px;border:0px;font-size:13.333333969116211px;vertical-align:baseline;background-color:transparent">NA</span><span class="" style="color:rgb(0,0,0);margin:0px;padding:0px;border:0px;font-size:13.333333969116211px;vertical-align:baseline;background-color:transparent">,</span><span class="" style="color:rgb(0,0,0);margin:0px;padding:0px;border:0px;font-size:13.333333969116211px;vertical-align:baseline;background-color:transparent"> </span><span class="" style="color:rgb(128,0,0);margin:0px;padding:0px;border:0px;font-size:13.333333969116211px;vertical-align:baseline;background-color:transparent">1</span><span class="" style="margin:0px;padding:0px;border:0px;font-size:13.333333969116211px;vertical-align:baseline;background-color:transparent"><font color="#000000">:</font><font color="#800000">3</font></span><span class="" style="color:rgb(0,0,0);margin:0px;padding:0px;border:0px;font-size:13.333333969116211px;vertical-align:baseline;background-color:transparent">,</span><span class="" style="color:rgb(0,0,0);margin:0px;padding:0px;border:0px;font-size:13.333333969116211px;vertical-align:baseline;background-color:transparent"> NA</span><span class="" style="color:rgb(0,0,0);margin:0px;padding:0px;border:0px;font-size:13.333333969116211px;vertical-align:baseline;background-color:transparent">))</span></code></pre>
</div><div style>As @flodel points out in the comments </div><div style><code style="margin:0px;padding:1px 5px;border:0px;font-size:13.333333969116211px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;color:rgb(68,68,68);line-height:17.77777862548828px">x[as.logical(a)]</code><span style="color:rgb(68,68,68);font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;font-size:13.333333969116211px;line-height:17.77777862548828px"> and </span><code style="margin:0px;padding:1px 5px;border:0px;font-size:13.333333969116211px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;color:rgb(68,68,68);line-height:17.77777862548828px">x[!!as.logical(a)]</code><br>
</div><div style>do not return the same value</div><div style><br></div><div style>I think this can be fixed rather simply by modifying one line in `[.data.table`, but confirmation would be helpful: </div><div style><br></div>
<div style><div> notjoin = FALSE</div><div> if (!missing(i)) {</div><div> isub = substitute(i)</div><div> .</div><div> .</div><div> .</div><div> if (is.logical(i)) {<br></div><div>
if (identical(i, NA)) </div><div> i = NA_integer_</div><div> else i[<a href="http://is.na">is.na</a>(i)] = FALSE <~~~ = FALSE || notjoin</div><div> }</div><div><div> .</div>
</div><div><div> .</div></div><div> }</div></div><div><br></div><div style>If that last copied line is changed </div><div style> from: else i[<a href="http://is.na">is.na</a>(i)] = FALSE</div><div style> to : else i[<a href="http://is.na">is.na</a>(i)] = FALSE || notjoin</div>
<div style>I believe this would resolve the issue. </div><div style><br></div><div style>The question is, would it introduce any other issues? Are there other corner cases we might be overlooking. </div><div style><br></div>
<div style>Cheers </div><div style>Rick<br></div><div style><br></div><div><br></div></div>