Skip to content

three data.table merge behavior inconsistency #4772

Closed

Description

@ajdamico

i looked around for related discussions and didn't find anything specific to this? i posted on SO and the accepted answerer there provided more detail about how it's likely a bug and also an easy fix-- https://stackoverflow.com/questions/64464386/three-data-table-merge-behavior-inconsistency/64464931#64464931

thanks very very much for this excellent software!

library(data.table)

x <- data.table( a = 1:3 )
y <- data.table( a = 2:4 )
z <- data.table( a = 3:5 )

# works
merge( x , y )
# works
merge( y , z )

# fails
merge( x , merge( y , z ) )
# Error in merge.data.table(x, merge(y, z)) :
#   A non-empty vector of column names for `by` is required.

# works
merge( merge( x , y ) , z )

Activity

  1. ecoRoland2 commented on Oct 22, 2020

    @ecoRoland2

    More minimal example:

    library(data.table)
    x <- data.table(a = 1:3)
    y <- data.table(a = 2:4, key = "a")
    
    merge(x, y)
    #Error in merge.data.table(x, y) : 
    #  A non-empty vector of column names for `by` is required.

    I believe you can simply change lines 35 and 37 of merge.R to if (length(by) == 0L).

  2. ecoRoland2 commented on Oct 22, 2020

    @ecoRoland2

    @ajdamico Please change the title to "merge fails with intersecting names if y is keyed"

  3. MichaelChirico commented on Sep 7, 2024

    @MichaelChirico
    Member

    For ease of future reference: this was actually closed by #5183.

  4. ajdamico commented on Sep 9, 2024

    @ajdamico
    ContributorAuthor

    thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions