的名單我有以下情況:複製data.tables
1)數據表
2)出於測試目的的名單我故意想(深)複製整個列表,包括數據表
3)我想從複製列表中取一些元素並添加一個新列。
下面是代碼:
library(data.table)
x = data.table(aaa = c(1,2))
y = data.table(bbb = c(1,2))
z = list(x,y)
zz = copy(z)
v = zz[[1]]
v = v[, newColumn := 1]
現在即時得到以下錯誤:
Error in `[.data.table`(res, , `:=`(xxx, TRUE)) :
(converted from warning) Invalid .internal.selfref detected and fixed
by taking a copy of the whole table so that := can add this new column
by reference. At an earlier point, this data.table has been copied by R
(or been created manually using structure() or similar). Avoid key<-,
names<- and attr<- which in R currently (and oddly) may copy the whole
data.table. Use set* syntax instead to avoid copying: ?set, ?setnames
and ?setattr. Also, in R<=v3.0.2, list(DT1,DT2) copied the entire DT1
and DT2 (R's list() used to copy named objects); please upgrade to
R>v3.0.2 if that is biting. If this message doesn't help, please report
to datatable-help so the root cause can be fixed.
我不明白的副本呼叫系統精確的用R處理的,它們是如何傳遞給數據。表,但不是這樣的:(?)
如果有人明確地使用複製功能,然後他/她意識到「按價值」和「按引用」之間存在差異的事實。所以他/她應該分發對象的真實副本。
因此,我認爲不應該有任何錯誤,我認爲這是一個錯誤發生的'錯誤'。那是對的嗎?
FW
您使用的是哪種版本的'R'和'data.table'? –