Skip to content

depending on order in j, x.* cols might not be found in non equi joins #2313

@franknarf1

Description

@franknarf1

An example:

library(data.table)
DT0 <- data.table(
  patient.id = c(1L, 2L, 1L, 1L, 2L, 2L, 2L),
  h.date = as.Date(c("2013/10/15", "2014/10/15", "2015/7/16", "2016/1/7", 
                                   "2015/12/20", "2015/12/25", "2016/2/10")))
setorder(DT0)
DT0[, `:=`(start.date = h.date - 365, end.date = h.date)]

# works:
DT0[DT0, on = .(patient.id, h.date >= start.date, h.date <= end.date), 
   .(x.h.date, patient.id, i.start.date, i.end.date, g = .GRP, .N)
, by=.EACHI]

# fails:
DT0[DT0, on = .(patient.id, h.date >= start.date, h.date <= end.date), 
   .(patient.id, i.start.date, i.end.date, g = .GRP, .N, x.h.date)
, by=.EACHI]
# Error in `[.data.table`(DT0, DT0, on = .(patient.id, h.date >= start.date,  : 
#   object 'x.h.date' not found

I see this result just from reordering the second line of the call -- the columns in j.

(Example from SO. I tried to come up with something simpler but couldn't figure it out.)

Metadata

Metadata

Labels

bugnon-equi joinsrolling, overlapping, non-equi joins

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions