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)

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

    No branches or pull requests

    Issue actions