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

Bug: unnest() #783

Closed
PathosEthosLogos opened this issue Nov 28, 2023 · 2 comments · Fixed by #784
Closed

Bug: unnest() #783

PathosEthosLogos opened this issue Nov 28, 2023 · 2 comments · Fixed by #784
Labels
bug Something isn't working

Comments

@PathosEthosLogos
Copy link

Discovered through https://community.rstudio.com/t/a-chr-column-has-vectors-and-atomic-values-how-can-i-turn-those-vectors-into-longer-pivoted-rows/177823

library(tidyverse) |> suppressPackageStartupMessages()


df_example <- tibble(a = list(c('a','b'),
                                 character(0),
                                 "z",
                                 c('y','z')),
                        id = list('aa', 'bb', 'cc', 'cc'))


df_example |>
  unnest(cols = a,keep_empty = TRUE)
#> # A tibble: 6 × 2
#>   a     id       
#>   <chr> <list>   
#> 1 a     <chr [1]>
#> 2 b     <chr [1]>
#> 3 <NA>  <chr [1]>
#> 4 z     <chr [1]>
#> 5 y     <chr [1]>
#> 6 z     <chr [1]>
library(tidytable) |> suppressPackageStartupMessages()

df_example <- tidytable(a = list(c('a','b'),
                                 character(0),
                                 "z",
                                 c('y','z')),
                        id = list('aa', 'bb', 'cc', 'cc'))


df_example |>
  unnest(a, keep_empty = TRUE)
#> # A tidytable: 5 × 1
#>   a    
#>   <chr>
#> 1 a    
#> 2 b    
#> 3 z    
#> 4 y    
#> 5 z

Created on 2023-11-28 with reprex v2.0.2

@markfairbanks markfairbanks added the bug Something isn't working label Nov 28, 2023
@markfairbanks
Copy link
Owner

markfairbanks commented Nov 29, 2023

Hmm it looks like a vector of length 0 should be kept when keep_empty = TRUE (currently it only works on NULL elements)

@markfairbanks
Copy link
Owner

All set - thanks for catching this

library(tidytable) |> suppressPackageStartupMessages()

df_example <- tidytable(a = list(c('a','b'),
                                 character(0),
                                 "z",
                                 c('y','z')),
                        id = list('aa', 'bb', 'cc', 'cc'))


df_example |>
  unnest(a, keep_empty = TRUE)
#> # A tidytable: 6 × 1
#>   a    
#>   <chr>
#> 1 a    
#> 2 b    
#> 3 <NA> 
#> 4 z    
#> 5 y    
#> 6 z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants