« first day (671 days earlier)      last day (3140 days later) » 

4:21 PM
@Arun Why doesn't mget work inside a data.table?

DT <- data.table(a=1:2, b=c("x", "y"))
DT[, get("a")]
#[1] 1 2
DT[, mget("a", inherits = TRUE)]
#Error: value for ‘a’ not found
I thought to answer this question, but my only idea with data.table would need mget. Or is there another way to refer to all columns of i that are in DT during a join for assignment by reference?
 
4:55 PM
@Roland good question. mget("a", as.environment(.SD)) should work. The j-exp is parsed and checked for get(), but not mget(). Therefore the SD environment isn't constructed with the required columns. Could you please file a report? I'll see if there's a quick fix. Else, will have to move to 1.9.8.
IIUC, we could do: cols <- names(D2)[-1L]; setkey(setDT(D1), k)[setDT(D2), (cols) := D2[, cols, with=FALSE]]??
Or even simpler: cols <- names(D2)[-1L]; setkey(setDT(D1), k)[D2, (cols) := D2[, cols]].
 
@Roland thanks!
 
@Arun Maybe you could add this as an answer? I'd guess the OP isn't dealing with huge datasets, but the data.table solution could be useful to others.
 
@Roland okay sure.
 
@Arun great!
 

« first day (671 days earlier)      last day (3140 days later) »