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

drop_na() incompatible with list-cols #280

Closed
tiernanmartin opened this issue Mar 8, 2017 · 2 comments
Closed

drop_na() incompatible with list-cols #280

tiernanmartin opened this issue Mar 8, 2017 · 2 comments
Labels
feature a feature request or enhancement rectangling 🗄️ converting deeply nested lists into tidy data frames

Comments

@tiernanmartin
Copy link

It seems that drop_na()'s dependency on stats::complete.cases is tripping it up when any list-cols are present:

library(tidyverse) 
library(purrr)

set.seed(1)

# Give mtcars a list-col and some NAs
mtcars_nas <- 
  mtcars %>% 
  rownames_to_column() %>% 
  mutate(LIST_COL = map(mpg, ~sample(LETTERS, nchar(.x)))) %>% 
  mutate(mpg = sample(c(mpg, rep(NA, 32)), n(), replace = TRUE)) %>% 
  select(rowname, mpg, LIST_COL) %>% 
  as_tibble

mtcars_nas
#> # A tibble: 32 × 3
#>              rowname   mpg  LIST_COL
#>                <chr> <dbl>    <list>
#> 1          Mazda RX4    NA <chr [2]>
#> 2      Mazda RX4 Wag  21.4 <chr [2]>
#> 3         Datsun 710  15.0 <chr [4]>
#> 4     Hornet 4 Drive  16.4 <chr [4]>
#> 5  Hornet Sportabout    NA <chr [4]>
#> 6            Valiant  19.7 <chr [4]>
#> 7         Duster 360    NA <chr [4]>
#> 8          Merc 240D  15.2 <chr [4]>
#> 9           Merc 230  10.4 <chr [4]>
#> 10          Merc 280    NA <chr [4]>
#> # ... with 22 more rows

# Try to drop the incomplete rows - fails
mtcars_nas %>% tidyr::drop_na()
#> Error in stats::complete.cases(data): invalid 'type' (list) of argument

Can you add a check to drop_na() to override this behavior?

@hadley hadley added the feature a feature request or enhancement label Jun 23, 2017
@jameshowison
Copy link

Unsurprisingly I also have this problem when I have NAs in a list column, so I'm commenting to add that possibility to the example above (where the NAs are in other, non-list columns).

@hadley
Copy link
Member

hadley commented Nov 16, 2017

NB: I'm pretty sure I worked around this problem in ggplot2, so the code should already exist.

@hadley hadley added the rectangling 🗄️ converting deeply nested lists into tidy data frames label Nov 16, 2017
@hadley hadley closed this as completed in 941a253 Nov 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement rectangling 🗄️ converting deeply nested lists into tidy data frames
Projects
None yet
Development

No branches or pull requests

3 participants