Skip to content

Commit

Permalink
Changing most drop_last to drop
Browse files Browse the repository at this point in the history
Changes in summarize require changes in how groups are dropped.  Also fixing for issue #54 raised in SWMPrExtension GitHub comments.
  • Loading branch information
DaveEslinger committed Feb 1, 2022
1 parent ed142c5 commit 3df8c21
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 20 deletions.
4 changes: 2 additions & 2 deletions R/annual_range.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ annual_range.swmpr <- function(swmpr_in
summarise(mean = mean(!! parm, na.rm = TRUE)
, min = min(!! parm, na.rm = TRUE)
, max = max(!! parm, na.rm = TRUE)
, .groups = "drop_last")
, .groups = "drop")

dat_month <- dat_day %>%
group_by(!! seas) %>%
Expand All @@ -158,7 +158,7 @@ annual_range.swmpr <- function(swmpr_in
, max_avg = mean(!! maxi, na.rm = TRUE)
, min = min(!! mini, na.rm = TRUE)
, max = max(!! maxi, na.rm = TRUE)
, .groups = "drop_last")
, .groups = "drop")

# ensure all factor levels are accounted for, even if there is no data
dat_month <- tidyr::complete(dat_month, !! seas)
Expand Down
6 changes: 3 additions & 3 deletions R/historical_daily_range.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ historical_daily_range.swmpr <- function(swmpr_in
dplyr::summarise(mean = mean(!! parm, na.rm = TRUE)
, min = min(!! parm, na.rm = TRUE)
, max = max(!! parm, na.rm = TRUE)
, .groups = "drop_last")
, .groups = "drop")

dat_all$julian_day <- lubridate::yday(dat_all$date)

Expand All @@ -169,14 +169,14 @@ historical_daily_range.swmpr <- function(swmpr_in
dplyr::summarise(mean = mean(!! avg, na.rm = TRUE)
, min = mean(!! mini, na.rm = TRUE)
, max = mean(!! maxi, na.rm = TRUE)
, .groups = "drop_last")
, .groups = "drop")

dat_hist_obs <- dat_all %>%
dplyr::group_by(!! jd) %>%
dplyr::summarise(mean = mean(!! avg, na.rm = TRUE)
, min = min(!! mini, na.rm = TRUE)
, max = max(!! maxi, na.rm = TRUE)
, .groups = "drop_last")
, .groups = "drop")

# account for missing julian days
if(length(dat_yr[1, ] < 365)){
Expand Down
12 changes: 6 additions & 6 deletions R/historical_range.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ historical_range.swmpr <- function(swmpr_in
dplyr::summarise(mean = mean(!! parm, na.rm = TRUE)
, min = min(!! parm, na.rm = TRUE)
, max = max(!! parm, na.rm = TRUE)
, .groups = "drop_last")
, .groups = "drop")

# Assign seasons
dat_all$season <- assign_season(dat_all$date, ...)
Expand All @@ -179,7 +179,7 @@ historical_range.swmpr <- function(swmpr_in
dplyr::summarise(mean = mean(!! avg, na.rm = TRUE)
, min = mean(!! mini, na.rm = TRUE)
, max = mean(!! maxi, na.rm = TRUE)
, .groups = "drop_last")
, .groups = "drop")

# Determine average min/max/mean for each month (for all years together)
if(data_type != 'nut') {
Expand All @@ -188,7 +188,7 @@ historical_range.swmpr <- function(swmpr_in
dplyr::summarise(mean = mean(!! avg, na.rm = TRUE)
, min = mean(!! mini, na.rm = TRUE)
, max = mean(!! maxi, na.rm = TRUE)
, .groups = "drop_last")
, .groups = "drop")

# Make some labels
lab_hist_rng <- paste('Daily Avg Range \n(', rng[[1]], '-', rng[[2]], ')', sep = '')
Expand All @@ -202,7 +202,7 @@ historical_range.swmpr <- function(swmpr_in
dplyr::summarise(mean = mean(!! avg, na.rm = TRUE)
, min = min(!! mini, na.rm = TRUE)
, max = max(!! maxi, na.rm = TRUE)
, .groups = "drop_last")
, .groups = "drop")

# Make some labels
lab_hist_rng <- paste('Seasonal Range \n(', rng[[1]], '-', rng[[2]], ')', sep = '')
Expand All @@ -218,14 +218,14 @@ historical_range.swmpr <- function(swmpr_in
dplyr::summarise(mean = mean(!! avg, na.rm = TRUE)
, min = mean(!! mini, na.rm = TRUE)
, max = mean(!! maxi, na.rm = TRUE)
, .groups = "drop_last")
, .groups = "drop")
} else {
dat_yr <- dat_yr %>%
dplyr::group_by(!! seas) %>%
dplyr::summarise(mean = mean(!! avg, na.rm = TRUE)
, min = min(!! mini, na.rm = TRUE)
, max = max(!! maxi, na.rm = TRUE)
, .groups = "drop_last")
, .groups = "drop")
}

# ensure all factor levels are accounted for, even if there is no data
Expand Down
6 changes: 3 additions & 3 deletions R/seasonal_barplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ seasonal_barplot.swmpr <- function(swmpr_in

dat_hist <- dat_hist %>%
dplyr::group_by(!! yr, !! seas) %>%
dplyr::summarise(result = sum(!! parm, na.rm = TRUE), .groups = "drop_last")
dplyr::summarise(result = sum(!! parm, na.rm = TRUE), .groups = "drop")

if(plot){
seas_col <- cols
Expand All @@ -165,10 +165,10 @@ seasonal_barplot.swmpr <- function(swmpr_in

if(season_facet) {
yr_mx <- dat_hist %>% group_by(!! yr, !! seas) %>%
summarise(max_val = sum(!! res, na.rm = TRUE), .groups = "drop_last")
summarise(max_val = sum(!! res, na.rm = TRUE), .groups = "drop")
} else {
yr_mx <- dat_hist %>% group_by(!! yr) %>%
summarise(max_val = sum(!! res, na.rm = TRUE), .groups = "drop_last")
summarise(max_val = sum(!! res, na.rm = TRUE), .groups = "drop")
}

mx <- ceiling(max(yr_mx$max_val) / 10) * 10 * 1.1
Expand Down
7 changes: 4 additions & 3 deletions R/seasonal_boxplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ seasonal_boxplot.swmpr <- function(swmpr_in
# Calc summary stat defined by FUN by season and day
dat_hist <- dat_hist %>%
group_by(!! seas, !! dt) %>%
summarise(result = FUN(!! parm), .groups = "drop_last")
summarise(result = FUN(!! parm), .groups = "drop")

# ensure all factor levels are accounted for, even if there is no data
dat_hist <- tidyr::complete(dat_hist, !! seas)
Expand Down Expand Up @@ -226,9 +226,10 @@ seasonal_boxplot.swmpr <- function(swmpr_in

dat_yr <- dat_yr %>%
dplyr::group_by(!! seas, !! dt) %>%
dplyr::summarise(result = FUN(!! parm), .groups = "drop_last") %>%
dplyr::summarise(result = FUN(!! parm), .groups = "drop") %>%
dplyr::group_by(!! seas) %>%
dplyr::summarise(med = stats::median(.data$result, na.rm = TRUE))
dplyr::summarise(med = stats::median(.data$result, na.rm = TRUE),
.groups = "drop")

pt_fill <- ifelse(data_type == 'nut', paste('Monthly Sample \n(', target_yr, ')', sep = '')
, paste('Median Daily ', stat_lab, ' \n(', target_yr, ')', sep = ''))
Expand Down
2 changes: 1 addition & 1 deletion R/seasonal_dot.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ seasonal_dot.swmpr <- function(swmpr_in
summarise(min = min(!! parm, na.rm = TRUE)
, mean = mean(!! parm, na.rm = TRUE)
, max = max(!! parm, na.rm = TRUE)
, .groups = "drop_last")
, .groups = "drop")

# ensure all factor levels are accounted for, even if there is no data
plt_data <- tidyr::complete(plt_data, !! seas)
Expand Down
2 changes: 1 addition & 1 deletion R/sk_seasonal.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ sk_seasonal.swmpr <- function(swmpr_in
# calc seasonal values
sk_data <- dat %>%
group_by(!! yr, !! seas) %>%
summarise(result = FUN(!! parm), .groups = "drop_last")
summarise(result = FUN(!! parm), .groups = "drop")

data_check <- sk_data %>% group_by(!! seas) %>% summarise(count = n())

Expand Down
2 changes: 1 addition & 1 deletion R/threshold_criteria_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ threshold_criteria_plot.swmpr <- function(swmpr_in

df_smooth <- dat %>%
group_by(year = lubridate::year(!! dt), month = lubridate::month(!! dt)) %>%
summarise(mean = mean(!! parm, na.rm = TRUE), .groups = "drop_last") %>%
summarise(mean = mean(!! parm, na.rm = TRUE), .groups = "drop") %>%
mutate(datetimestamp = paste(year, '-', month, '-', '01', ' ', '0:00', sep = ''))

df_smooth$datetimestamp <- as.POSIXct(df_smooth$datetimestamp)
Expand Down

0 comments on commit 3df8c21

Please sign in to comment.