Skip to content

non-equi join breaks inconsistently when using .SD  #3635

@UweBlock

Description

@UweBlock

I have asked on SO for an explanation of this inconsistent behaviour. @franknarf1 has replied that this might be a bug which could be related to #1989.

Depending on the "direction" or "type" of join, using j = .SD throws an error:

library(data.table)
(d1 <- fread("a,b\n1,11\n6,16"))
#    a  b
# 1: 1 11
# 2: 6 16
(d2 <- data.table(r = 1:5, s = seq(0, 20, 5)))
#    r  s
# 1: 1  0
# 2: 2  5
# 3: 3 10
# 4: 4 15
# 5: 5 20

# case A

d1[d2, on = .(a <= s, b >= s)]
#     a  b r
# 1:  0  0 1
# 2:  5  5 2
# 3: 10 10 3
# 4: 10 10 3
# 5: 15 15 4
# 6: 20 20 5

d1[d2, on = .(a <= s, b >= s), j = .SD]
# Error in [.data.table(d1, d2, on = .(a <= s, b >= s), j = .SD) :
# column(s) not found: a

# case B

d2[d1, on = .(s >= a, s <= b)]
#    r s s.1
# 1: 2 1  11
# 2: 3 1  11
# 3: 3 6  16
# 4: 4 6  16

d2[d1, on = .(s >= a, s <= b), j = .SD]
#    r s
# 1: 2 1
# 2: 3 1
# 3: 3 6
# 4: 4 6

I have reproduced this behaviour with R version 3.6.0 and data.table versions 1.11.8, 1.12.2, and 1.12.3 on

Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.5 LTS

and with R version 3.6.0 and data.table version 1.12.3 on

Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)

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