rwd_agg: Class to specify how to aggregate RiverWare data

Description Usage Arguments Details Aggregation Specification Custom Period Functions See Also Examples

View source: R/rwd_agg.R

Description

rwd_agg() creates a RiverWare data aggregator (rwd_agg) object, which lets users specify how specific RiverWare slots should be aggregated.

Usage

1
rwd_agg(x = NULL, rdfs = NULL)

Arguments

x

A data.frame with required column names and valid entries; see Details and Aggregation Specification sections.

rdfs

A vector of rdf names; see Details and Aggregation Specification sections.

Details

rwd_agg objects can be created in three ways:

  1. By providing a data.frame, with the following expected columns file, slot, period, summary, eval, t_s, and variable. Each row in the data.frame should include all of the information for how each individual slot will be aggregated. See the Aggregation Specification section below for details on how to specify each column.

  2. By providing a vector of rdf files. If specified in this manor, all of the slots in each rdf file will be read in to a rwtbl, but will not be aggregated/summarized.

    In this case, the variable names are automatically constructed from the ObjectSlot names. The variable names are constructed as the all lower case version of the object_slot name. If the slot name is "Pool Elevation", it is shortened to "pe", otherwise the full object and slot name are used. If there are any spaces, they are replaced with underscores.

  3. By reading in a csv file with read_rwd_agg(). This csv file must have the correct column names and meet other requirements described below. To ensure it has the correct column names, rwd_agg_template() can be used to create a blank csv file for the user to fill in.

Aggregation Specification

In order to specify how each slot should be aggregated, each column should include specific keywords, which are described below. It is up to the user to specify which rdf file contains each slot. In a general case, the user specifies the slot that is found in a specific rdf file (file). A summary function is applied to a subset period of the slot, and then compared (eval) to a threshold (t_s) and saved as the variable.

For example, to determine if the minimum water year elevation at Lake Powell is below elevation 3550 feet, the following would be specified:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
data.frame(
  file = "KeySlots.rdf",
  slot = "Powell.Pool Elevation",
  period = "wy",
  summary = "min",
  eval = "<",
  t_s = 3550,
  variable = "powellLt3550",
  stringsAsFactors = FALSE
)

Custom Period Functions

Users can specify custom period functions to make it easier to group months together in custom ways. For example a function could return all of the summer months, or the more complicated case groups months across different calendar years together. In fact, wy() is an example of a function that does this; another example might be grouping December - February together for winter months.

The custom period function should return a list with three elements:

See the "RWDataPlyr Workflow" vignette for example implementations of both the summer and winter custom functions described above.

See Also

rwd_agg_template(), read_rwd_agg()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# determine if Powell's minimum water year elevation is < 3550'
rwd_agg(
  data.frame(
    file = "KeySlots.rdf",
    slot = "Powell.Pool Elevation",
    period = "wy",
    summary = "min",
    eval = "<",
    t_s = 3550,
    variable = "powellLt3550",
    stringsAsFactors = FALSE
  )
)

# get all the monthly slots in KeySlots.rdf
rwd_agg(rdfs = "KeySlots.rdf")

RWDataPlyr documentation built on April 17, 2020, 9:06 a.m.