The PivotFilters class allows multiple filter conditions relating to different data frame columns to be combined, i.e. a PivotFilters object typically contains multiple PivotFilter objects.

## Format

R6Class object.

## Details

As well as acting as a container for multiple filter conditions, the PivotFilters class also contains logic for combining filter. The action parameter in many of the methods controls how two filters are combined.
Most common cases:
(1) When working out the rowColFilters for each pivot table cell, the filters from the row and column leaf groups are combined using action="intersect".
(2) When combining the rowColFilters with calculation filters the action could be any of (in order of most typical) "intersect", "replace" or "union".
"intersect" would apply additional restrictions, e.g. see the example in the Calculations vignette that has a measure for weekend trains only.
"replace" would apply when doing things like percentage of row total calculations - again, see example in the calculations vignette
"union" is probably much less likely (hard to envisage many situations when that would be needed).
(3) In custom calculation functions, the action could be any of "intersect", "replace" or "union".
NOTE: pivottabler does not allow complex conditions to be built up, such as ((A=X) or (B=Y)) and (C=2) since there is complex precedence involved and conditions like this are not typical of pivot tables. If they were really needed, a workaround would be to use a custom calculation function and include this logic in that function.
See Appendix 2 vignette for many more complex calculation details.

## Active bindings

count

The number of PivotFilter objects in this PivotFilters object.

filters

A list of PivotFilter objects in this PivotFilters object.

isALL

If TRUE, this PivotFilters object matches all data.

isNONE

If TRUE, this PivotFilters object matches no data.

filteredVariables

The names of the variables that are filtered by this PivotFilters object.

filteredValues

A list of the criteria values for each of the variables filtered by this PivotFilters object, where the list element names are the variable names.

## Methods

### Method new()

Create a new PivotFilters object, optionally adding a filter.

No return value.

### Method keepOnlyFiltersFor()

Remove the filters for all variables except those specified.

#### Arguments

variableNames

A character vector specifying the variable names for which the filter criteria will be cleared. Filter criteria for all other variables will be retained.

No return value.

### Method getFilter()

Find a filter with the specified variable name.

PivotFilters$getFilter(variableName = NULL) #### Arguments variableName The variable name to find a filter for. #### Returns A PivotFilter object that filters on the specified variable. ### Method isFilterMatch() Tests whether this PivotFilters object matches specified criteria. #### Usage PivotFilters$isFilterMatch(
matchMode = "simple",
variableNames = NULL,
variableValues = NULL
)

#### Arguments

matchMode

Either "simple" (default) or "combinations".
"simple" is used when matching only one variable-value, multiple variable-value combinations are effectively logical "OR", i.e. any one single PivotFilter match means the PivotFilters object is a match.
"combinations" is used when matching for combinations of variable values, multiple variable-value combinations are effectively logical "AND", i.e. there must be a matching PivotFilter for every variable name / variable values criteria specified.
See the "Finding and Formatting" vignette for graphical examples.

variableNames

The variable name(s) to find a filter for. This can be a vector containing more than one variable name.

variableValues

A list specifying the variable names and values to find, e.g. variableValues=list("PowerType"=c("DMU", "HST")).

#### Returns

TRUE if this filters object matches the specified criteria, FALSE otherwise.

### Method setFilters()

Update the value of this PivotFilters object with the filters from the specified PivotFilters object, either intersecting, replacing or unioning the filter criteria.

#### Arguments

filter

A PivotFilter object.

action

Specifies how the criteria defined in filter should be combined with the existing filter criteria. Must be one of "intersect", "replace" or "union".

No return value.

### Method setFilterValues()

Update the value of this PivotFilters object with additional filter criteria, either intersecting, replacing or unioning the filter criteria.

#### Arguments

filter

A PivotFilter object.

No return value.

### Method getFilteredDataFrame()

Filters the specified data frame using the filters defined in this PivotFilters object and returns the results as another data frame.

#### Returns

A copy of this PivotFilters object.

### Method asList()

Return the contents of this object as a list for debugging.

#### Returns

A JSON representation of various object properties.

### Method asString()

Return a representation of this object as a character value.

#### Arguments

deep

Whether to make a deep clone.

## Examples

pt <- PivotTable$new() # ... # PivotFilters constructor allows a filter to be defined filters <- PivotFilters$new(pt, variableName="Year", values=2017)
# Create a new filter
filter <- PivotFilter$new(pt, variableName="Country", values="England") # Combine the filters filters$setFilter(filter)
# filters now contains criteria for both Year and Country
# Now add another filter, this time via an alternative method