[datatable-help] .SD is locked

Arunkumar Srinivasan aragorn168b at gmail.com
Mon Nov 18 00:29:14 CET 2013


Hm, nice catch! In this special case, the value returned is from this code: 

jval = eval(jsub, SDenv, parent.frame())

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:

x <- as.data.table(BOD)
xx <- x[, {print(tracemem(.SD)); .SD}, .SDcols="Time"]
[1] "<0x7fa4e9a518f0>"
tracemem(xx)
[1] "<0x7fa4e9a518f0>"


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.

Arun


On Monday, November 18, 2013 at 12:11 AM, Michael Nelson wrote:

> I don't believe this is to be expected.
> 
> A bug report should be filed (it is present in 1.8.10 on CRAN as well)
> 
> .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
> 
> 
> ________________________________________
> From: datatable-help-bounces at lists.r-forge.r-project.org (mailto:datatable-help-bounces at lists.r-forge.r-project.org) [datatable-help-bounces at lists.r-forge.r-project.org (mailto:datatable-help-bounces at lists.r-forge.r-project.org)] on behalf of G See [gsee000 at gmail.com (mailto:gsee000 at gmail.com)]
> Sent: Monday, 18 November 2013 9:32 AM
> To: datatable-help at lists.r-forge.r-project.org (mailto:datatable-help at lists.r-forge.r-project.org)
> Subject: [datatable-help] .SD is locked
> 
> Hi,
> 
> Is the following error expected?
> 
> > library(data.table)
> data.table 1.8.11 For help type: help("data.table")
> > x <- as.data.table(BOD)
> > xx <- x[, .SD, .SDcols="Time"]
> > xx[, Time:=as.numeric(Time)]
> > 
> 
> Error in `[.data.table`(xx, , `:=`(Time, as.numeric(Time))) :
> .SD is locked. Using := in .SD's j is reserved for possible future
> use; a tortuously flexible way to modify by group. Use := in j
> directly to modify by group by reference.
> > sessionInfo()
> 
> R version 3.0.2 (2013-09-25)
> Platform: x86_64-pc-linux-gnu (64-bit)
> 
> locale:
> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
> [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
> [9] LC_ADDRESS=C LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
> 
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
> 
> other attached packages:
> [1] data.table_1.8.11
> 
> loaded via a namespace (and not attached):
> [1] plyr_1.8 reshape2_1.2.2 stringr_0.6.2
> 
> 
> Thanks,
> Garrett
> _______________________________________________
> datatable-help mailing list
> datatable-help at lists.r-forge.r-project.org (mailto:datatable-help at lists.r-forge.r-project.org)
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
> _______________________________________________
> datatable-help mailing list
> datatable-help at lists.r-forge.r-project.org (mailto:datatable-help at lists.r-forge.r-project.org)
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
> 
> 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20131118/0a833430/attachment.html>


More information about the datatable-help mailing list