|
6 | 6 | #' |
7 | 7 | #' @noRd |
8 | 8 |
|
9 | | - |
10 | | -agg_custom <- function(data, groups, fun, agg.scale){ |
| 9 | +agg_custom <- function(data, groups, fun, agg.scale) { |
11 | 10 | out = atlantistools::agg_data(data = data, groups = groups, fun = fun) %>% |
12 | | - mutate(date = as.POSIXct(time*365*86400, origin = '1964-01-01 00:00:00',tz = 'UTC')) |
| 11 | + mutate( |
| 12 | + date = as.POSIXct( |
| 13 | + time * 365 * 86400, |
| 14 | + origin = '1964-01-01 00:00:00', |
| 15 | + tz = 'UTC' |
| 16 | + ) |
| 17 | + ) |
13 | 18 |
|
14 | | - if(agg.scale == 'month') { |
15 | | - out$time.agg = as.numeric(factor(format(out$date,format = '%m'))) |
16 | | - }else if(agg.scale == 'year'){ |
| 19 | + if (agg.scale == 'month') { |
| 20 | + out$time.agg = as.numeric(factor(format(out$date, format = '%m'))) |
| 21 | + } else if (agg.scale == 'year') { |
17 | 22 | out$time.agg = as.numeric(factor(format(out$date, format = '%Y'))) |
18 | | - }else{ |
19 | | - out$time.agg = out$time*365 |
| 23 | + } else { |
| 24 | + out$time.agg = out$time * 365 |
20 | 25 | } |
21 | 26 |
|
22 | | - match.cols = c(groups[-which(groups == 'time')],'time.agg') |
| 27 | + match.cols = c(groups[-which(groups == 'time')], 'time.agg') |
23 | 28 | out.agg = out %>% |
24 | 29 | group_by_at(match.cols) %>% |
25 | | - dplyr::summarise(time = floor(min(time)), |
26 | | - atoutput = mean(atoutput,na.rm=T),.groups="drop") |
27 | | - dplyr::select(all_of(c(groups,'atoutput'))) |
| 30 | + dplyr::summarise( |
| 31 | + time = floor(min(time)), |
| 32 | + atoutput = mean(atoutput, na.rm = T), |
| 33 | + .groups = "drop" |
| 34 | + ) |
| 35 | + dplyr::select(all_of(c(groups, 'atoutput'))) |
28 | 36 |
|
29 | 37 | return(out.agg) |
30 | 38 | } |
0 commit comments