Repository navigation
Description
Binding integer64 with integer/numeric works silently and correctly, whereas binding IDate with Date fails and so does binding of attribute cols where one/more tables are empty (0-rows).
integer 64 case:
require(data.table) # 1.12.2 current CRAN version, but I don't think things change with current devel)
require(bit64)
ll <- list(data.table(a=1, b=as.integer64(2)), data.table(a=2, b=1))
str(rbindlist(ll))
# Classes ‘data.table’ and 'data.frame': 2 obs. of 2 variables:
# $ a: num 1 2
# $ b:integer64 2 1
# - attr(*, ".internal.selfref")=<externalptr> The 2nd element's col b seems to be implicitly converted to integer64 type without a message/warning.
IDate case
ll <- list(data.table(a=1, b=as.IDate(Sys.Date())), data.table(a=2, b=Sys.Date()))
rbindlist(ll)
# Error in rbindlist(ll) :
# Class attribute on column 2 of item 2 does not match with column 2 of item 1.First element's b column is IDate and 2nd is Date and there's an error.
0-row data.table case:
ll <- list(data.table(a=1, b=Sys.time()), data.table(a=numeric(0), b=numeric(0)))
rbindlist(ll)
# Error in rbindlist(ll) :
# Class attribute on column 2 of item 2 does not match with column 2 of item 1.Even if the empty table has a wrong type, it could be skipped as it doesn't really make it to the final table. (This used to work in previous versions when fill=TRUE -- probably accidental).
In essence, I'd think it'd be immensely convenient to have an argument to ignore strict attributes check, e.g., ignore.attr=FALSE (together with a global option so that code that has been written with old+lenient behaviour work continue to work) which would simply retain the first element's class.
And if the default is to be strict, then, the first case should also error, for consistency.
Activity
statquant commentedon Sep 30, 2020
Since data.table 1.13.0 and fread reading dates as IDate I come across this issue all the time.
I think rbindlist should indeed ignore attributes in cases like this
pkress commentedon Nov 24, 2020
I just wanted to bump this issue as well - it's a real pain to have to specify
dt[, date.col:=as.Date(date.col)]before binding data.tables together.jrausch12 commentedon Dec 5, 2020
therosko commentedon Oct 6, 2021
I can only agree with this. Seems like a completely unnecessary step to add to a process, if the attributes could have just been ignored.
Nj221102 commentedon Mar 20, 2024
I m working on this issue, will raise a PR soon.