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

Comments

Projects
None yet
3 participants
@tiernanmartin

tiernanmartin commented Mar 8, 2017

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 label Jun 23, 2017

@jameshowison

This comment has been minimized.

jameshowison commented Jul 20, 2017

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

This comment has been minimized.

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 trees 🌲 label Nov 16, 2017

@hadley hadley closed this in 941a253 Nov 20, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment