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

unnest_wider() doesn't work with data frame columns #1188

Closed
DavisVaughan opened this issue Nov 3, 2021 · 0 comments · Fixed by #1200
Closed

unnest_wider() doesn't work with data frame columns #1188

DavisVaughan opened this issue Nov 3, 2021 · 0 comments · Fixed by #1200
Labels
bug an unexpected problem or unintended behavior rectangling 🗄️ converting deeply nested lists into tidy data frames

Comments

@DavisVaughan
Copy link
Member

It isn't the intentional usage for this function, but it theoretically should work if we had a perfect implementation:

library(tidyr)

df <- tibble(a = 1:3, b = tibble(x = 1:3, y = 1:3))
df
#> # A tibble: 3 × 2
#>       a   b$x    $y
#>   <int> <int> <int>
#> 1     1     1     1
#> 2     2     2     2
#> 3     3     3     3

unnest_wider(df, b)
#> New names:
#> * `` -> ...1
#> * `` -> ...2
#> * `` -> ...3
#> New names:
#> * `` -> ...1
#> * `` -> ...2
#> * `` -> ...3
#> Error: Assigned data `map(data[[col]], vec_to_wide, col = col, names_sep = names_sep)` must be compatible with existing data.
#> x Existing data has 3 rows.
#> x Assigned data has 2 rows.
#> ℹ Only vectors of size 1 are recycled.

# Pretty sure it should look like:
df$b <- vctrs::vec_chop(df$b)
unnest_wider(df, b)
#> # A tibble: 3 × 3
#>       a     x     y
#>   <int> <int> <int>
#> 1     1     1     1
#> 2     2     2     2
#> 3     3     3     3

# Because that is sort of equivalent to what this does:
df$b <- 1:3
unnest_wider(df, b)
#> New names:
#> * `` -> ...1
#> New names:
#> * `` -> ...1
#> New names:
#> * `` -> ...1
#> # A tibble: 3 × 2
#>       a  ...1
#>   <int> <int>
#> 1     1     1
#> 2     2     2
#> 3     3     3

Created on 2021-11-03 by the reprex package (v2.0.1)

@DavisVaughan DavisVaughan added bug an unexpected problem or unintended behavior rectangling 🗄️ converting deeply nested lists into tidy data frames labels Nov 3, 2021
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 rectangling 🗄️ converting deeply nested lists into tidy data frames
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant