Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
franknarf1 opened this issue Aug 21, 2017 · 0 comments · Fixed by #2583
Closed

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

franknarf1 opened this issue Aug 21, 2017 · 0 comments · Fixed by #2583
Assignees
Labels
bug non-equi joins rolling, overlapping, non-equi joins
Milestone

Comments

@franknarf1
Copy link
Contributor

franknarf1 commented Aug 21, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug non-equi joins rolling, overlapping, non-equi joins
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants