我有一个生成数据表的函数,如下所示:
requiere(dplyr)
requiere(data.table)
f <- function() data.table(A = sample(1:3))
下一步是多次应用此函数,然后对所有数据表进行行绑定:
dts <- lapply(1:20, function(x) f()) %>% bind_rows
现在,如果我尝试在dts
中创建一个新变量,我会收到一条警告消息:
> dts[, new := 1]
Warning message:
In `[.data.table`(dts, , `:=`(new, 1)) :
Invalid .internal.selfref detected and fixed by taking a (shallow) copy of the data.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.
如何避免此警告?