-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
Creating a new variable in a data.table which was created from an existing data.table using .SD in j gives a .SD locked error if i is supplied but no error if i is not supplied.
dt <- data.table(a = 1:10)
# Works as expected
sub_dt <- dt[,.SD]
sub_dt[,b := 1]
# Gives .SD is locked error
sub_dt2 <- dt[a == 5,.SD]
sub_dt2[,b := 1]
The address for .SD and sub_dt2 are the same.
# prints address and returns value
printSDaddr <-function(x){
print(address(x))
x
}
# Address of .SD and sub_dt are different
sub_dt <- dt[,printSDaddr(.SD)]
address(sub_dt)
# Address of .SD and sub_dt2 are the same
sub_dt2 <- dt[a == 5,printSDaddr(.SD)]
address(sub_dt2)
R version 3.1.3 (2015-03-09)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server 2008 R2 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] setlr_0.1 data.table_1.9.5 XLConnect_0.2-11 XLConnectJars_0.2-9
loaded via a namespace (and not attached):
[1] chron_2.3-47 codetools_0.2-11 curl_0.9.2 devtools_1.8.0 digest_0.6.8 foreach_1.4.2
[7] git2r_0.10.1 httr_1.0.0 iterators_1.0.7 knitr_1.10.5 magrittr_1.5 memoise_0.2.1
[13] plyr_1.8.3 R6_2.1.1 Rcpp_0.12.0 reshape2_1.4.1 rJava_0.9-6 rversions_1.0.1
[19] stringi_0.4-1 stringr_1.0.0 tools_3.1.3 xml2_0.1.1