You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Updating a data.table by reference provides inconsistent results for single-row data.tables:
library(data.table) ##1.12.8 - same results in masterdt= data.table(a=3L)
dt[, b:=3L]
dt[, b2:= .(3L)]
dt[, `:=`( b3=3L)]
dt[, `:=`(b4= .(3L))]
dt#> a b b2 b3 b4#> <int> <int> <int> <int> <list>#> 1: 3 3 3 3 3
Basically, the var := .(...) version seems to coerce the RHS to an atomic if ... evaluates to an atomic and is the same number of rows as the data.table. This differs from `:=`(var = .(...)) which appears to always make var a list column
I see LHS := RHS similar to transform(), within(), or $<-. In each case, the RHS is taken as is. Therefore, I expect V1 := 1L to be an atomic whereas V1 := list(1L) to be a list column.
should not give a list column in the n == 1 case. The `:=`(col = val) notation does not work like this, therefore there is no need to remove the outermost list().
Updating a
data.table
by reference provides inconsistent results for single-rowdata.table
s:Basically, the
var := .(...)
version seems to coerce the RHS to an atomic if...
evaluates to an atomic and is the same number of rows as thedata.table
. This differs from`:=`(var = .(...))
which appears to always makevar
a list columnI have not had a chance to dig deep, but this line from
[.data.table
may help explain why`:=`(var = .(...))
results in a list.data.table/R/data.table.R
Lines 1047 to 1053 in ad7b67c
This was observed while investigating #4568 although I am not sure how related they are.
The text was updated successfully, but these errors were encountered: