NOAA-OCM / SWMPrExtension

Functions for Analyzing and Plotting SWMP Estuary Monitoring Data from the NERR System archive at
http://cdmo.baruch.sc.edu/
Other
12 stars 5 forks source link

Drop groups before completing #54

Closed DavisVaughan closed 2 years ago

DavisVaughan commented 2 years ago

We are planning on releasing tidyr 1.2.0 towards the end of this month.

We noticed in revdeps that this package was broken. An easy way to reproduce is to install the dev version of tidyr and run this example:

library(SWMPrExtension)
#> Loading required package: SWMPr
#> Loading required package: ggplot2
#> Loading required package: zoo
#> 
#> Attaching package: 'zoo'
#> The following objects are masked from 'package:base':
#> 
#>     as.Date, as.Date.numeric

dat <- elksmwq
dat <- qaqc(dat, qaqc_keep = c('0', '3', '5'))

x <-
  seasonal_boxplot(dat, param = 'do_mgl')
#> Warning in seasonal_boxplot.swmpr(dat, param = "do_mgl"): No historical range
#> specified. Entire time series will be used.
#> Warning in seasonal_boxplot.swmpr(dat, param = "do_mgl"): No target year
#> provided
#> Error: Problem with `summarise()` input `..1`.
#> ℹ `..1 = complete(data = dplyr::cur_data(), ..., fill = fill, explicit = explicit)`.
#> x object 'season' not found
#> ℹ The error occurred in group 1: season = Jan.

The problem comes down to the fact that you were trying to call complete() with a grouped data frame, and you were trying to complete on the group column. This is actually not well defined, as complete() completes "within" each group, so you really shouldn't have access to the group variables. The previous behavior was problematic in many cases (see https://github.com/tidyverse/tidyr/issues/396 and https://github.com/tidyverse/tidyr/issues/966), so we've made a fix to ensure that complete() works correctly with grouped data frames in all cases. This fix comes with the restriction that now you can't specify the group variables in the call to complete().

It looks like everything would work fine if you just drop the groups entirely, so that is what this PR does.

This should work on both the current and development version of tidyr, so you should be able to go ahead and do a patch release. We would greatly appreciate if you could do this so we can release tidyr! Thank you!

DaveEslinger commented 2 years ago

Thanks for this fix. Our NOAA OCM procedures currently keep me from pulling directly from a non-NOAA contributor. However, I will make the fix as you show in our copy and add you as a contributor. Thanks again! Dave