Gsee, just adding the line:
if (identical(jval, SDenv$.SD)) jval = copy(jval)
before `return(jval)` seems to fix this (and all tests also complete without
any issues). If you're in a hurry for fix, you could just add it for now.
I'll test it again later and commit with other changes I've staged locally.
It'd still be nice to file this as a bug so that it could be tracked.
Best,
Arun
On Monday, November 18, 2013 at 12:29 AM, Arunkumar Srinivasan wrote:
> 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: [email protected]
> > (mailto:[email protected])
> > [[email protected]
> > (mailto:[email protected])] on behalf of G
> > See [[email protected] (mailto:[email protected])]
> > Sent: Monday, 18 November 2013 9:32 AM
> > To: [email protected]
> > (mailto:[email protected])
> > 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
> > [email protected]
> > (mailto:[email protected])
> > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
> > _______________________________________________
> > datatable-help mailing list
> > [email protected]
> > (mailto:[email protected])
> > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
> >
> >
> >
>
>
_______________________________________________
datatable-help mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help