PivotFilters | R Documentation |
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.
R6Class
object.
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.
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.
new()
Create a new 'PivotFilters' object, optionally adding a filter.
PivotFilters$new( parentPivot = NULL, variableName = NULL, type = "ALL", values = NULL )
parentPivot
The pivot table that this 'PivotFilters' instance belongs to.
variableName
The name of the column in the data frame that this filter applies to. Specify 'NULL' to skip adding a filter.
type
Must be either "ALL", "VALUES" or "NONE". "VALUES" is the most common type and means the data is filtered to a subset of values. "ALL" means there is no filtering, i.e. all values match. "NONE" means there can be no matching values/data.
values
A single data value or a vector of multiple data values that the filter will match on.
A new 'PivotFilters' object.
clearFilters()
Remove all filters from this 'PivotFilters' object.
PivotFilters$clearFilters()
No return value.
keepOnlyFiltersFor()
Remove the filters for all variables except those specified.
PivotFilters$keepOnlyFiltersFor(variableNames = NULL)
variableNames
A character vector specifying the variable names to retain the filter criteria for. Filter criteria for all other variables will be cleared.
No return value.
removeFiltersFor()
Remove the filters for the specified variables.
PivotFilters$removeFiltersFor(variableNames = NULL)
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.
getFilter()
Find a filter with the specified variable name.
PivotFilters$getFilter(variableName = NULL)
variableName
The variable name to find a filter for.
A 'PivotFilter' object that filters on the specified variable.
isFilterMatch()
Tests whether this 'PivotFilters' object matches specified criteria.
PivotFilters$isFilterMatch( matchMode = "simple", variableNames = NULL, variableValues = NULL )
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"))'.
'TRUE' if this filters object matches the specified criteria, 'FALSE' otherwise.
setFilters()
Update the value of this 'PivotFilters' object with the filters from the specified 'PivotFilters' object, either intersecting, replacing or unioning the filter criteria.
PivotFilters$setFilters(filters = NULL, action = "replace")
filters
A 'PivotFilters' object.
action
Specifies how the criteria defined in 'filters' should be combined with the existing filter criteria. Must be one of "intersect", "replace" or "union".
No return value.
setFilter()
Update the value of this 'PivotFilters' object with the filters from the specified 'PivotFilter' object, either intersecting, replacing or unioning the filter criteria.
PivotFilters$setFilter(filter = NULL, action = "replace")
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.
setFilterValues()
Update the value of this 'PivotFilters' object with additional filter criteria, either intersecting, replacing or unioning the filter criteria.
PivotFilters$setFilterValues( variableName = NULL, type = "ALL", values = NULL, action = "replace" )
variableName
The name of the column in the data frame that this criteria applies to.
type
Must be either "ALL", "VALUES" or "NONE".
values
A single data value or a vector of multiple data values that comprise the additional filter criteria.
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.
addFilter()
Add a new 'PivotFilter' object to the filter list in this 'PivotFilters' object.
PivotFilters$addFilter(filter = NULL)
filter
A 'PivotFilter' object.
No return value.
getFilteredDataFrame()
Filters the specified data frame using the filters defined in this 'PivotFilters' object and returns the results as another data frame.
PivotFilters$getFilteredDataFrame(dataFrame = NULL)
dataFrame
A data frame to filter.
A data frame filtered according to the criteria in this 'PivotFilters' object.
getCopy()
Create a copy of this 'PivotFilters' object.
PivotFilters$getCopy()
A copy of this 'PivotFilters' object.
asList()
Return the contents of this object as a list for debugging.
PivotFilters$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
PivotFilters$asJSON()
A JSON representation of various object properties.
asString()
Return a representation of this object as a character value.
PivotFilters$asString(includeVariableName = TRUE, seperator = ", ")
includeVariableName
'TRUE' (default) to include the variable name in the string.
seperator
A character value used when concatenating multiple filters.
A character summary of various object properties.
clone()
The objects of this class are cloneable with this method.
PivotFilters$clone(deep = FALSE)
deep
Whether to make a deep clone.
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
filters$setFilterValues(variableName="Product", values="Cadbury Dairy Milk
Chocolate 100g")
# filters now contains criteria for Year, Country and Product
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.