<div>Hm, nice catch! In this special case, the value returned is from this code:
</div><div><br></div><div>jval = eval(jsub, SDenv, parent.frame())</div><div><br></div><div>Since `jsub = .SD`, this evaluates to .SD ('s value). However, since `jval` remains untouched, a copy is not made (I think). This can be seen with a `tracemem` statement:</div><div><br></div><div>x <- as.data.table(BOD)</div><div>xx <- x[, {print(tracemem(.SD)); .SD}, .SDcols="Time"]</div><div>[1] "<0x7fa4e9a518f0>"</div><div>tracemem(xx)</div>
<div><div><div>[1] "<0x7fa4e9a518f0>"</div></div><div><br></div><div>Basically `xx` is `.SD` and therefore is 'locked'. I guess a fix would be to check this and make a copy on return. Not sure.</div><div><br></div><div>Arun</div><div><br></div></div>
<p style="color: #A0A0A8;">On Monday, November 18, 2013 at 12:11 AM, Michael Nelson wrote:</p>
<blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px;">
<span><div><div><div>I don't believe this is to be expected.</div><div><br></div><div>A bug report should be filed (it is present in 1.8.10 on CRAN as well)</div><div><br></div><div>.SD is locked so you can't "mess" with it within a call to `[.data.table`, but this "locked" status should not be retained following the completion of that call</div><div><br></div><div><br></div><div>________________________________________</div><div>From: <a href="mailto:datatable-help-bounces@lists.r-forge.r-project.org">datatable-help-bounces@lists.r-forge.r-project.org</a> [<a href="mailto:datatable-help-bounces@lists.r-forge.r-project.org">datatable-help-bounces@lists.r-forge.r-project.org</a>] on behalf of G See [<a href="mailto:gsee000@gmail.com">gsee000@gmail.com</a>]</div><div>Sent: Monday, 18 November 2013 9:32 AM</div><div>To: <a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a></div><div>Subject: [datatable-help] .SD is locked</div><div><br></div><div>Hi,</div><div><br></div><div>Is the following error expected?</div><div><br></div><blockquote type="cite"><div>library(data.table)</div></blockquote><div>data.table 1.8.11 For help type: help("data.table")</div><blockquote type="cite"><div><div>x <- as.data.table(BOD)</div><div>xx <- x[, .SD, .SDcols="Time"]</div><div>xx[, Time:=as.numeric(Time)]</div></div></blockquote><div>Error in `[.data.table`(xx, , `:=`(Time, as.numeric(Time))) :</div><div> .SD is locked. Using := in .SD's j is reserved for possible future</div><div>use; a tortuously flexible way to modify by group. Use := in j</div><div>directly to modify by group by reference.</div><blockquote type="cite"><div>sessionInfo()</div></blockquote><div>R version 3.0.2 (2013-09-25)</div><div>Platform: x86_64-pc-linux-gnu (64-bit)</div><div><br></div><div>locale:</div><div> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C</div><div> [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8</div><div> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8</div><div> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C</div><div> [9] LC_ADDRESS=C LC_TELEPHONE=C</div><div>[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C</div><div><br></div><div>attached base packages:</div><div>[1] stats graphics grDevices utils datasets methods base</div><div><br></div><div>other attached packages:</div><div>[1] data.table_1.8.11</div><div><br></div><div>loaded via a namespace (and not attached):</div><div>[1] plyr_1.8 reshape2_1.2.2 stringr_0.6.2</div><div><br></div><div><br></div><div>Thanks,</div><div>Garrett</div><div>_______________________________________________</div><div>datatable-help mailing list</div><div><a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a></div><div><a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a></div><div>_______________________________________________</div><div>datatable-help mailing list</div><div><a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a></div><div><a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a></div></div></div></span>
</blockquote>
<div>
<br>
</div>