Skip to content

nested_join() to preserve the class of the nested data? #6295

Closed
@huizezhang-sherry

Description

@huizezhang-sherry

In the example below, if I nest dt2, the rowwise_df class is preserved in each list column element, I'm wondering if nest_join() should have a similar behavior?

# set up `dt1` with an id column and some random numbers
set.seed(123)
dt1 <- tibble::tibble(
  id = c(1,2,3),
  a = rnorm(n = 3)
)

# set up `dt2` as a rowwise dataframe with `id2` nested inside `id1` column 
set.seed(123)
dt2 <- tibble::tibble(
  id = rep(c(1,2,3), each = 3),
  id2  = rep(c("a", "b", "c"), 3),
  b = rnorm(n = 9)
) |>
  dplyr::rowwise()

# nesting `dt2` gives each element in data as a `rowwise_df`
dt2 |> tidyr::nest(data = -id)
#> # A tibble: 3 × 2
#>      id data                
#>   <dbl> <list>              
#> 1     1 <rowwise_df [3 × 2]>
#> 2     2 <rowwise_df [3 × 2]>
#> 3     3 <rowwise_df [3 × 2]>

# but `nest_join()` doesnt not preserve the `rowwwise_df` class 
dt1 |> dplyr::nest_join(dt2, by = "id")
#> # A tibble: 3 × 3
#>      id      a dt2             
#>   <dbl>  <dbl> <list>          
#> 1     1 -0.560 <tibble [3 × 2]>
#> 2     2 -0.230 <tibble [3 × 2]>
#> 3     3  1.56  <tibble [3 × 2]>

Created on 2022-06-13 by the reprex package (v2.0.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviortables 🧮joins and set operations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions