Skip to content

expand_grid with tibbles fails depending on values #1116

@djbirke

Description

@djbirke

I am trying to create a tibble that contains all combinations of its elements, except for some nesting. In doing so, I encountered the following sensitivity of expand_grid with respect to its contents.

Is this a bug?

tidyr::expand_grid(
  dplyr::tibble(
    fruit = c("Apple", "Banana"),
    fruit_id = c("a", "b")
  ),
  dplyr::tibble(
    status_id = c("c", "d"),
    status = c("cut", "devoured")
  )
)
#> # A tibble: 4 x 4
#>   fruit  fruit_id status_id status  
#>   <chr>  <chr>    <chr>     <chr>   
#> 1 Apple  a        c         cut     
#> 2 Apple  a        d         devoured
#> 3 Banana b        c         cut     
#> 4 Banana b        d         devoured

tidyr::expand_grid(
  dplyr::tibble(
    fruit = c("Apple", "Banana"),
    fruit_id = c("a", "b")
  ),
  dplyr::tibble(
    status_id = c("c", "d"),
    status = c("cut_neatly", "devoured"),
  )
)
#> Error: Column name `dplyr::tibble(...)` must not be duplicated.
#> Use .name_repair to specify repair.

Created on 2021-04-27 by the reprex package (v1.0.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorgrids #️⃣expanding, nesting, crossing, ...

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions