Skip to content

non-equi join breaks when using get or mget #1989

@franknarf1

Description

@franknarf1

This came up on SO:

library(data.table)
a <- data.table(Company_ID = c(1,1,1,1),
            salary = c(2000, 3000, 4000, 5000))

#   Company_ID salary
# 1:          1   2000
# 2:          1   3000
# 3:          1   4000
# 4:          1   5000

b <- data.table(cat = c(1,2),
            LB = c(0, 3000),
            UB = c(3000,5000),
            rep = c("Bob","Alice"))
#    cat   LB   UB   rep
# 1:   1    0 3000   Bob
# 2:   2 3000 5000 Alice

b[a, on=.(LB <= salary, UB > salary), nomatch=0, get("salary")]
# Error in `[.data.table`(b, a, on = .(LB <= salary, UB > salary), nomatch = 0,  : 
#   column(s) not found: LB

# or 
b[a, on=.(LB <= salary, UB > salary), nomatch=0, mget(union(names(a), names(b)))]
# Error in `[.data.table`(b, a, on = .(LB <= salary, UB > salary), nomatch = 0,  : 
#   column(s) not found: LB    

Also...

ucols = union(names(a), names(b))
b[a, on=.(LB <= salary, UB > salary), nomatch=0, ..ucols]
# Error in `[.data.table`(b, a, on = .(LB <= salary, UB > salary), nomatch = 0,  : 
#   column(s) not found: LB    

# and even...
b[a, on=.(LB <= salary, UB > salary), nomatch=0, c("Company_ID", "salary", "cat", "LB", "UB", "rep")]
# Error in `[.data.table`(b, a, on = .(LB <= salary, UB > salary), nomatch = 0,  : 
#   column(s) not found: LB    

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugnon-equi joinsrolling, overlapping, non-equi joins

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions