Skip to content

Problems writing cross-join in dplyr #4206

@JohnMount

Description

@JohnMount

Sometimes one wants a cross-join, but the obvious way to write that in dplyr does not work (though it does work for dbplyr).

suppressPackageStartupMessages(library("dplyr"))
#> Warning: package 'dplyr' was built under R version 3.5.2
packageVersion("dplyr")
#> [1] '0.8.0.1'
packageVersion("dbplyr")
#> [1] '1.3.0'

d <- data.frame(g = c("a", "b"),
                stringsAsFactors = FALSE)


left_join(d, d, by = character(0))
#> Error: `by` must specify variables to join by

db <- DBI::dbConnect(RSQLite::SQLite(),
                     ":memory:")
d2 <- dplyr::copy_to(db, d, "d2")

left_join(d2, d2, by = character(0))
#> # Source:   lazy query [?? x 2]
#> # Database: sqlite 3.22.0 [:memory:]
#>   g.x   g.y  
#>   <chr> <chr>
#> 1 a     a    
#> 2 a     b    
#> 3 b     a    
#> 4 b     b

DBI::dbDisconnect(db)

Created on 2019-02-20 by the reprex package (v0.2.1)

Activity

romainfrancois

romainfrancois commented on Mar 4, 2019

@romainfrancois
Member

joins are not part of our immediate focus for the next series. This is probably something that can be incubated in another package for the time being.

hadley

hadley commented on Jan 11, 2020

@hadley
Member

In the join refactoring I'm working on currently, this turns out to be a trivial fix so it's likely to make it in 1.0.0

added a commit that references this issue on Jan 12, 2020
b712e5b
added a commit that references this issue on Jan 13, 2020
1e76e8a
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

    featurea feature request or enhancementtables 🧮joins and set operations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @hadley@romainfrancois@JohnMount

      Issue actions

        Problems writing cross-join in dplyr · Issue #4206 · tidyverse/dplyr