Skip to content

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

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.)

Activity

  1. added a commit that references this issue on Jan 23, 2018
    b81a379
  2. added this to the milestone on Jan 23, 2018
  3. added a commit that references this issue on Jan 23, 2018
    b336e75
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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