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

Error on unnamed values if names_sep isn't provided #1462

Merged

Conversation

DavisVaughan
Copy link
Member

Closes #1367

So now we get:

library(tidyr)

df <- tribble(
  ~x, ~y,
  1, c(11, 12, 13),
  2, 21
)
df |> unnest_wider(y)
#> Error in `unnest_wider()`:
#> ! Can't unnest elements with missing names.
#> ℹ Supply `names_sep` to generate automatic names.

Also fixes an issue where partially unnamed elements weren't being patched with automatic names. Instead they were getting name-repaired by vctrs, which ended up generating a strange (and not useful) combination of names.

library(tidyr)

df <- tribble(
  ~x, ~y,
  1, c(11, b = 12, 13),
  2, 21
)

# before
df |> unnest_wider(y, names_sep = "_")
#> New names:
#> • `` -> `...1`
#> • `` -> `...3`
#> # A tibble: 2 × 5
#>       x y_...1   y_b y_...3   y_1
#>   <dbl>  <dbl> <dbl>  <dbl> <dbl>
#> 1     1     11    12     13    NA
#> 2     2     NA    NA     NA    21

# after
df |> unnest_wider(y, names_sep = "_")
#> # A tibble: 2 × 4
#>       x   y_1   y_b   y_3
#>   <dbl> <dbl> <dbl> <dbl>
#> 1     1    11    12    13
#> 2     2    21    NA    NA

Created on 2023-01-12 with reprex v2.0.2.9000

Copy link
Member

@hadley hadley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks much better.

Will need to check for any revdep breakage.

@DavisVaughan
Copy link
Member Author

DavisVaughan commented Jan 13, 2023

"a324805f-c91c-43fc-9b50-405affcbfe24" - No failures from this!

And fix automatic name generation on partially missing names
@DavisVaughan DavisVaughan force-pushed the feature/unnest-wider-names-sep-error branch from debe900 to fabc363 Compare January 13, 2023 16:01
@DavisVaughan DavisVaughan merged commit 71ec2d6 into tidyverse:main Jan 13, 2023
@DavisVaughan DavisVaughan deleted the feature/unnest-wider-names-sep-error branch January 13, 2023 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should unnest_wider() default to some separator for unnamed entries?
2 participants