Skip to contents

Takes data with a column in a time format (posix or date) and aggregates into groups defined by breaks while retaining theme and spatial information. Much of the setup and checks mirrors that of theme_aggregate() and spatial_aggregate(), and then passes to general_aggregate().

Usage

temporal_aggregate(
  dat,
  breaks = "all_time",
  timecol = "infer",
  groupers,
  aggCols,
  funlist,
  geonames = NULL,
  prefix = "temporal_",
  failmissing = TRUE,
  auto_ewr_PU = FALSE,
  ...
)

Arguments

dat

sf or tibble or dataframe of values to aggregate, with necessary grouping information for non-temporal axes (e.g. scenario, location, theme). Not necessarily the same as data in general_aggregate()- this function makes necessary adjustments to the data before calling general_aggregate()

breaks

breaks for the time groupings. default 'all_time' collapses over the whole period, otherwise as in base::cut.POSIXt() (takes the character options there, or time objects)

timecol

name of the column with time in it. Default 'infer' infers which it is by looking for POSIXt or Date types.

groupers

as in general_aggregate(), with the note that these should be all grouping columns except any spatial information. Spatial information is automatically added to groupers before passing to general_aggregate().

aggCols

an expression for the columns to aggregate (the data columns). See selectcreator for formats

funlist

a list of functions and their arguments used to aggregate the data. See functionlister for creation in many cases. The situation with a bare anonymous function, e.g. ~mean(., na.rm = T) is not supported because we need a name. Use a named list if using anonymous functions, e.g. list(mean = ~mean(., na.rm = T)). If using functions with a data-variable argument, e.g. weighted.mean with a column of weights, we now (as of dplyr 1.1) have some workarounds. One option is if specified as a function argument, the function can just go in as a bare name or anonymous. If specified elsewhere, it can be wrapped in rlang::quo(), e.g. agglist <- rlang::quo(list(mean = mean, wm = ~weighted.mean(., weight_column_name, na.rm = T))). If it isn't, there is now an internal workaround to add that on that seems to be stable but may cause unforeseen issues. This workaround also allows building custom aggregation functions (not-anonymous) with the data-variable argument either exposed or hardcoded (see SpatialWeightedMean()). The error checks for names do not work for quosures, so make sure you name the list if using rlang::quo().

geonames

additional columns of information to persist through the aggregation. Cannot change with the main groupers. Developed to persist information about polygons through subsequent theme aggregations, but could be more general

prefix

prefix character, differs from general_aggregate() in that default is 'temporal_' instead of 'agg_'.

failmissing

logical, default TRUE: fail if the requested grouping or aggregation columns not exist. If FALSE, proceed with those that do exist and silently drop those that don't. Similar to tidyselect::all_of() vs tidyselect::any_of() in tidyselect

auto_ewr_PU

logical, default FALSE. If TRUE, automatically infers whether this is an EWR dataset and has not yet been spatially aggregated. If so, applies grouping by 'planning_unit_name' and SWSDLName' since EWRs are defined in those units. The preferred solution is to include it in groupers here (for on-off), or in multi_aggregate() to use group_until. If none of those solutions happen, though, it aborts to prevent incorrect pooling over rows in different planning units and sdl units.

...

arguments passed to the aggregation functions. This is very limited, and does not work with data arguments under most conditions. Almost always better to specify explicitly when building funlist, but works OK with simple functions, e.g. passing na.rm = TRUE to mean

Value

a tibble (possibly sf if fed an sf) with columns for the grouping variables aggregated into the time periods specified by breaks