This seems as fread bug, but I am not sure.
This example reproduce my problem. I have a function where I read a data.table and return it in a list. i use list to group other results in the same structure. Here my code:
ff.fread <- function(){
dt = fread("x
1
2
")
list(dt=dt)
}
DT.f <- ff.fread()$dt
Now when I try to add a new column to DT.f, it works but I get a warning message:
DT.f[,y:=1:2]
Warning message:
In `[.data.table`(DT.f, , `:=`(y, 1:2)) :
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.1.0, list(DT1,DT2) copied
the entire DT1 and DT2 (R's list() used to copy named objects); please upgrade
to R>=v3.1.0 if that is biting. If this message doesn't help, please report to
datatable-help so the root cause can be fixed.
Note the if I create the data.table manually I don't have this warning. This works fine for example:
ff <- function(){
list(dt=data.table(x=1:2))
}
DT <- ff()$dt
DT[,y:=1:2]
Or if I don't return the result of fread within a list , it works also fine
ff.fread <- function(){
dt = fread("x
1
2
")
dt
}