I have a function that generates a data table, like this:
requiere(dplyr)
requiere(data.table)
f <- function() data.table(A = sample(1:3))
The next step is to apply this function several times and then row bind all the data tables:
dts <- lapply(1:20, function(x) f()) %>% bind_rows
Now, if I try to create a new variable in dts
, I get a warning message:
> 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.
How can I avoid this warning?