Skip to content

Don't inspect i=CJ(...) names in DT[CJ(...), on=] joins #2081

@franknarf1

Description

@franknarf1

Looking again at #1596 , one point against it is that some folks may be taking advantage of the default V1, V2, ... names, so auto-assigning different names would break their code.

One alternative, that would address my primary use-case, would be for CJ to not need names during a join:

library(data.table)
DT = unique(data.table(datasets::CO2)[, .(Plant, Type, Treatment)])
setkey(DT, Plant, Type)

# good -- no names needed using list
DT[.("Mc1", "Mississippi"), .N, by=.EACHI]

# good -- no names needed using CJ and (implicitly) on = key
DT[CJ(Plant, Type, unique=TRUE), .N, by = .EACHI]

# bad -- breaks for explicit on = key 
DT[CJ(Plant, Type, unique=TRUE), on=key(DT)]

# bad -- breaks for on=some-non-key
DT[CJ(Plant, Treatment, unique = TRUE), on=.(Plant, Treatment)]

So I guess I'm asking for an exception in [.data.table that ignores names in i when i=CJ(...), similar to how names are ignored with list inputs or when on= is implicitly the key.

Of course, my desired syntax would also work if FR #1596 went through.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementjoinsUse label:"non-equi joins" for rolling, overlapping, and non-equi joins

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions