Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
huizezhang-sherry opened this issue Jun 13, 2022 · 4 comments · Fixed by #6371
Closed

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

huizezhang-sherry opened this issue Jun 13, 2022 · 4 comments · Fixed by #6371
Labels
bug an unexpected problem or unintended behavior tables 🧮 joins and set operations

Comments

@huizezhang-sherry
Copy link

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)

@DavisVaughan

This comment was marked as outdated.

@huizezhang-sherry

This comment was marked as outdated.

@DavisVaughan

This comment was marked as outdated.

@DavisVaughan DavisVaughan reopened this Jun 14, 2022
@hadley hadley added bug an unexpected problem or unintended behavior tables 🧮 joins and set operations labels Jul 21, 2022
@hadley
Copy link
Member

hadley commented Jul 26, 2022

Minimal reprex:

library(dplyr, warn.conflicts = FALSE)

df1 <- tibble(id = 1:3, a = 4:6)
df2 <- rowwise(tibble(id = c(2, 3, 3), b = 7:9))

out <- df1 |> dplyr::nest_join(df2, by = "id", multiple = "all")
class(out$df2[[2]])
#> [1] "tbl_df"     "tbl"        "data.frame"

Created on 2022-07-26 by the reprex package (v2.0.1)

hadley added a commit that referenced this issue Jul 26, 2022
hadley added a commit that referenced this issue Jul 26, 2022
hadley added a commit that referenced this issue Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior tables 🧮 joins and set operations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants