| PivotFilterOverrides {pivottabler} | R Documentation |
R6 class that defines a set of filter overrides.
Description
The 'PivotFilterOverrides' class contains multiple PivotFilter
objects that can be used later to override a set of filters, e.g. in a
pivot table calculation.
Format
R6Class object.
Details
Each cell in a pivot table has context (i.e. filters) coming from the row and column groups that are applicable to the cell. The 'PivotFilterOverrides' class contains several different ways of changing this filter criteria as part of a calculation. In most use cases, only one of the available approaches will be used.
Active bindings
removeAllFiltersTRUE to remove all existing filters before applying any other and/replace/or filters.
keepOnlyFiltersForSpecify the names of existing variables to retain the filters for. All other filters will be removed.
removeFiltersForSpecify the names of variables to remove filters for.
overrideFunctionA custom R function to amend the filters in each cell.
countAndThe number of 'PivotFilters' that will be combined with other pivot filters by intersecting their lists of allowed values.
countReplaceThe number of 'PivotFilters' that will be combined with other pivot filters by entirely replacing existing PivotFilter objects.
countOrThe number of 'PivotFilters' that will be combined with other pivot filters by unioning their lists of allowed values.
countTotalThe total number of 'PivotFilters' that will be combined with other pivot filters.
andFiltersThe 'PivotFilters' that will be combined with other pivot filters by intersecting their lists of allowed values.
replaceFiltersThe 'PivotFilters' that will be combined with other pivot filters by entirely replacing existing PivotFilter objects.
orFiltersThe 'PivotFilters' that will be combined with other pivot filters by unioning their lists of allowed values.
allFiltersThe complete set of 'PivotFilters' that will be combined with other pivot filters.
Methods
Public methods
Method new()
Create a new 'PivotFilterOverrides' object.
Usage
PivotFilterOverrides$new( parentPivot = NULL, removeAllFilters = FALSE, keepOnlyFiltersFor = NULL, removeFiltersFor = NULL, overrideFunction = NULL, filter = NULL, variableName = NULL, type = "ALL", values = NULL, action = "replace" )
Arguments
parentPivotThe pivot table that this 'PivotFilterOverrides' instance belongs to.
removeAllFiltersSpecifies whether to clear all existing filters, before applying the filter overrides. Default value 'FALSE'
keepOnlyFiltersForA character vector specifying the variable names to retain the filter criteria for. Filter criteria for all other variables will be cleared.
removeFiltersForA character vector specifying the variable names for which the filter criteria will be cleared. Filter criteria for all other variables will be retained.
overrideFunctionA custom R function which will be invoked for each cell to modify the filters before the calculation is carried out.
filterA PivotFilter object containing filter criteria which will be combined with the current set of filters using the specified combine method.
variableNameThe variable name for a new filter to apply to. Specified in conjunction with the 'type' and 'values' parameters.
typeThe type of a new filter to apply, must be either "ALL", "VALUES" or "NONE".
valuesA single data value or a vector of multiple data values that a new filter will match on.
actionSpecifies how the new filter defined in 'filter' (or 'variableName', 'type' and 'values') should be combined with the existing filter criteria for the cell. Must be one of "intersect", "replace" or "union".
Returns
A new 'PivotFilterOverrides' object.
Method add()
Add additional filter criteria into this 'PivotFilterOverrides' object. Either 'filter' is specified, or 'variableName', 'type' and 'values' are specified.
Usage
PivotFilterOverrides$add( filter = NULL, variableName = NULL, type = "ALL", values = NULL, action = "replace" )
Arguments
filterA 'PivotFilter' to take criteria from.
variableNameThe variable name the additional criteria applies to.
typeThe type of the additional filter criteria, must be either "ALL", "VALUES" or "NONE".
valuesA single data value or a vector of multiple data values that compromise the additional filter criteria.
actionSpecifies how the additional filter should be combined with the existing filter criteria for the cell. Must be one of "intersect", "replace" or "union".
Returns
No return value.
Method apply()
Apply the filter overrides to an existing 'PivotFilters' object.
Usage
PivotFilterOverrides$apply(filters = NULL, cell = NULL)
Arguments
filtersA 'PivotFilters' object to apply the filter overrides to.
cellA 'PivotCell' object representing the cell that the 'filters' relate to.
Returns
No return value.
Method asList()
Return the contents of this object as a list for debugging.
Usage
PivotFilterOverrides$asList()
Returns
A list of various object properties.
Method asJSON()
Return the contents of this object as JSON for debugging.
Usage
PivotFilterOverrides$asJSON()
Returns
A JSON representation of various object properties.
Method asString()
Return a representation of this object as a character value.
Usage
PivotFilterOverrides$asString(includeVariableName = TRUE, seperator = ", ")
Arguments
includeVariableName'TRUE' (default) to include the variable name in the string.
seperatorA character value used when concatenating multiple filter overrides.
Returns
A character summary of various object properties.
Method clone()
The objects of this class are cloneable with this method.
Usage
PivotFilterOverrides$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Examples
pt <- PivotTable$new()
# ...
# PivotFilterOverrides constructor allows a filter to be defined
# e.g. to enable %of row or column type calculations
filterOverrides <- PivotFilterOverrides$new(pt, keepOnlyFiltersFor="Volume")
# Alternatively/in addition, create a new filter
filter <- PivotFilter$new(pt, variableName="Country", values="England")
# Add the filter to the set of overrides
filterOverrides$add(filter=filter, action="replace")