Skip to content

diff(factor) by group causes STRING_ELT error #3315

@MichaelChirico

Description

@MichaelChirico

Reproducing for me on latest dev. I guess diff(factor) is not meaningful and should be an error, but it's going through and causing an error later down the line.

set.seed(32940)
NN = 7e5
KK = 4e4
TT = 25

DT = data.table(
  id = sample(KK, NN, TRUE),
  tt = sample(TT, NN, TRUE),
  ff = factor(sample(3, NN, TRUE))
)
DT[ , diff(ff), by = id]

Error in rbindlist(l, use.names, fill, idcol) :
STRING_ELT() can only be applied to a 'character vector', not a 'NULL'

traceback() shows it's coming from print:

6: rbindlist(l, use.names, fill, idcol) at data.table.R#2673
5: data.table::.rbind.data.table(...)
4: rbind(deparse.level, ...)
3: rbind(head(x, topn), tail(x, topn)) at print.data.table.R#53
2: print.data.table(x)
1: function (x, ...) 
   UseMethod("print")(x)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions