Let's say I have 2 tables and their names are:
csvs <- c("jan", "feb")
I am looking to create a new column within each table that denotes their period by simply taking the df's name. My attempt is:
lapply(csvs, function(x) eval(as.name(x))[, period := x])
Yes, I would prefer an apply over a loop. However, I am receiving the error below:
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 was created manually using structure() or similar). Avoid 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. If this message doesn't help, please report your use case to the data.table issue tracker so the root cause can be fixed or this message improved.
I have looked up shallow copy but do not understand how it applies to my context. Any help would be appreciated.
eval(as.name(x))
withget(x)
, do you still get the same error? – rps1227