Group output from naniar using dplyr, nesting/unnesting, compatibility with newer version of R

291 views Asked by At

I had a piece of R script running to get an overview on missing values in a repeated measures data frame. I used naniar and dplyr from the tidyverse and it worked fine. I used the combination to group the output by different factors (e.g. study, day, participant,...):

miss_trigger <- data_mlm_npu_filter[,c("Trigger_counter", "stadi_AU")] %>% 
  group_by(Trigger_counter) %>%
  miss_var_summary() 

Now, some months later, I first got the warning message

#Warning message:
#  `cols` is now required.
#Please use `cols = c(data)` 

After searching for the warning message, I found that there has change something with nesting/unnesting but this information did not help me to fix the warning/what changes to apply to my code.

And now after updating R to 3.6.2, I am just getting:

Error in group_by_fun(data, .fun = miss_var_summary()) : 
  could not find function "group_by_fun"

The miss_var_summary function itself works without problems. So, I would really just like to group my output from naniar as before. What do I have to do? Apparently I am missing a key information or understanding of the packages I am using on how to fix this myself.

1

There are 1 answers

0
Nick Tierney On

This was a bug introduced by a new version of tidyr, this should now work:

library(naniar)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

oceanbuoys %>% 
  group_by(year) %>% 
  miss_var_summary()
#> # A tibble: 14 x 4
#> # Groups:   year [2]
#>     year variable   n_miss pct_miss
#>    <dbl> <chr>       <int>    <dbl>
#>  1  1997 air_temp_c     77   20.9  
#>  2  1997 latitude        0    0    
#>  3  1997 longitude       0    0    
#>  4  1997 sea_temp_c      0    0    
#>  5  1997 humidity        0    0    
#>  6  1997 wind_ew         0    0    
#>  7  1997 wind_ns         0    0    
#>  8  1993 humidity       93   25.3  
#>  9  1993 air_temp_c      4    1.09 
#> 10  1993 sea_temp_c      3    0.815
#> 11  1993 latitude        0    0    
#> 12  1993 longitude       0    0    
#> 13  1993 wind_ew         0    0    
#> 14  1993 wind_ns         0    0

Created on 2020-05-14 by the reprex package (v0.3.0)

devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.0 (2020-04-24)
#>  os       macOS Mojave 10.14.6        
#>  system   x86_64, darwin17.0          
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_AU.UTF-8                 
#>  ctype    en_AU.UTF-8                 
#>  tz       Australia/Melbourne         
#>  date     2020-05-14                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version     date       lib source                          
#>  assertthat    0.2.1       2019-03-21 [1] CRAN (R 4.0.0)                  
#>  backports     1.1.6       2020-04-05 [1] CRAN (R 4.0.0)                  
#>  callr         3.4.3       2020-03-28 [1] CRAN (R 4.0.0)                  
#>  cli           2.0.2       2020-02-28 [1] CRAN (R 4.0.0)                  
#>  colorspace    1.4-2       2020-02-27 [1] R-Forge (R 4.0.0)               
#>  crayon        1.3.4       2017-09-16 [1] CRAN (R 4.0.0)                  
#>  desc          1.2.0       2018-05-01 [1] CRAN (R 4.0.0)                  
#>  devtools      2.3.0       2020-04-10 [1] CRAN (R 4.0.0)                  
#>  digest        0.6.25      2020-02-23 [1] CRAN (R 4.0.0)                  
#>  dplyr       * 0.8.99.9002 2020-05-04 [1] Github (tidyverse/dplyr@8710f8a)
#>  ellipsis      0.3.0       2019-09-20 [1] CRAN (R 4.0.0)                  
#>  evaluate      0.14        2019-05-28 [1] CRAN (R 4.0.0)                  
#>  fansi         0.4.1       2020-01-08 [1] CRAN (R 4.0.0)                  
#>  fs            1.4.1       2020-04-04 [1] CRAN (R 4.0.0)                  
#>  generics      0.0.2       2018-11-29 [1] CRAN (R 4.0.0)                  
#>  ggplot2       3.3.0       2020-03-05 [1] CRAN (R 4.0.0)                  
#>  glue          1.4.0       2020-04-03 [1] CRAN (R 4.0.0)                  
#>  gtable        0.3.0       2019-03-25 [1] CRAN (R 4.0.0)                  
#>  highr         0.8         2019-03-20 [1] CRAN (R 4.0.0)                  
#>  htmltools     0.4.0       2019-10-04 [1] CRAN (R 4.0.0)                  
#>  knitr         1.28        2020-02-06 [1] CRAN (R 4.0.0)                  
#>  lifecycle     0.2.0       2020-03-06 [1] CRAN (R 4.0.0)                  
#>  magrittr      1.5         2014-11-22 [1] CRAN (R 4.0.0)                  
#>  memoise       1.1.0       2017-04-21 [1] CRAN (R 4.0.0)                  
#>  munsell       0.5.0       2018-06-12 [1] CRAN (R 4.0.0)                  
#>  naniar      * 0.5.1       2020-04-30 [1] CRAN (R 4.0.0)                  
#>  pillar        1.4.4       2020-05-05 [1] CRAN (R 4.0.0)                  
#>  pkgbuild      1.0.8       2020-05-07 [1] CRAN (R 4.0.0)                  
#>  pkgconfig     2.0.3       2019-09-22 [1] CRAN (R 4.0.0)                  
#>  pkgload       1.0.2       2018-10-29 [1] CRAN (R 4.0.0)                  
#>  prettyunits   1.1.1       2020-01-24 [1] CRAN (R 4.0.0)                  
#>  processx      3.4.2       2020-02-09 [1] CRAN (R 4.0.0)                  
#>  ps            1.3.3       2020-05-08 [1] CRAN (R 4.0.0)                  
#>  purrr         0.3.4       2020-04-17 [1] CRAN (R 4.0.0)                  
#>  R6            2.4.1       2019-11-12 [1] CRAN (R 4.0.0)                  
#>  Rcpp          1.0.4.6     2020-04-09 [1] CRAN (R 4.0.0)                  
#>  remotes       2.1.1       2020-02-15 [1] CRAN (R 4.0.0)                  
#>  rlang         0.4.6       2020-05-02 [1] CRAN (R 4.0.0)                  
#>  rmarkdown     2.1         2020-01-20 [1] CRAN (R 4.0.0)                  
#>  rprojroot     1.3-2       2018-01-03 [1] CRAN (R 4.0.0)                  
#>  scales        1.1.1       2020-05-11 [1] CRAN (R 4.0.0)                  
#>  sessioninfo   1.1.1       2018-11-05 [1] CRAN (R 4.0.0)                  
#>  stringi       1.4.6       2020-02-17 [1] CRAN (R 4.0.0)                  
#>  stringr       1.4.0       2019-02-10 [1] CRAN (R 4.0.0)                  
#>  testthat      2.3.2       2020-03-02 [1] CRAN (R 4.0.0)                  
#>  tibble        3.0.1       2020-04-20 [1] CRAN (R 4.0.0)                  
#>  tidyr         1.0.3       2020-05-07 [1] CRAN (R 4.0.0)                  
#>  tidyselect    1.1.0       2020-05-11 [1] CRAN (R 4.0.0)                  
#>  usethis       1.6.1       2020-04-29 [1] CRAN (R 4.0.0)                  
#>  utf8          1.1.4       2018-05-24 [1] CRAN (R 4.0.0)                  
#>  vctrs         0.2.99.9011 2020-05-04 [1] Github (r-lib/vctrs@0ca806c)    
#>  visdat        0.5.3       2019-02-15 [1] CRAN (R 4.0.0)                  
#>  withr         2.2.0       2020-04-20 [1] CRAN (R 4.0.0)                  
#>  xfun          0.13        2020-04-13 [1] CRAN (R 4.0.0)                  
#>  yaml          2.2.1       2020-02-01 [1] CRAN (R 4.0.0)                  
#> 
#> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library