Aggregate along theme dimension
theme_aggregate.Rd
Aggregation along the theme dimension uses causal mappings to aggregate from
lower to higher levels. This function sets up the data with specific prep for
the way the theme dimension works, and then wraps general_aggregate()
. Many
of the arguments here are just passed through to general aggregate.
Usage
theme_aggregate(
dat,
from_theme,
to_theme,
groupers,
aggCols,
funlist,
causal_edges,
geonames = NULL,
failmissing = TRUE,
auto_ewr_PU = FALSE,
...
)
Arguments
- dat
sf or tibble or dataframe of values to aggregate, with necessary grouping information for non-theme axis (e.g. scenario, location). Not necessarily the same as
data
ingeneral_aggregate()
- this function makes necessary adjustments to the data before callinggeneral_aggregate()
- from_theme
character, column name of the theme level the data is currently in
- to_theme
character, column name of the theme level to aggregate to
- groupers
as in
general_aggregate()
, with the note that these should be all grouping columns except the theme column specified byto_theme
and any spatial information. These are both automatically added togroupers
before passing togeneral_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 ofdplyr
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 inrlang::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 (seeSpatialWeightedMean()
). The error checks for names do not work for quosures, so make sure you name the list if usingrlang::quo()
.- causal_edges
the causal links between theme levels. Needs to include
from_theme
andto_theme
, but can also include others. Creates the theme grouping- 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- failmissing
logical, default
TRUE
: fail if the requested grouping or aggregation columns not exist. IfFALSE
, proceed with those that do exist and silently drop those that don't. Similar totidyselect::all_of()
vstidyselect::any_of()
intidyselect
- 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 inmulti_aggregate()
to usegroup_until
. If none of those solutions happen, though, it aborts to prevent incorrect pooling over rows in different planning units and sdl units.- ...
passed to
general_aggregate()