PivotCalculator | R Documentation |
The 'PivotCalculator' class has various functions and methods that assist with calculating the value of a cell or cells in a pivot table.
R6Class
object.
This class contains all of the logic necessary for evaluating calculations. For batch mode calculations, it makes use of the 'PivotBatchCalculator' class to carry out the calculation batches, then retrieves the results from the relevant batch for each calculation. For sequential mode calculations, this class carries out the calculations. Where a pivot table contains some cells that can be evaluated in batch mode and some that cannot, this class contains the appropriate logic to use the relevant calculation mode in each case, preferring to use batch mode where possible, unless this has been disabled in the pivot table settings. There are many utility methods in this class that are thin wrappers around methods in other classes. This simplifies calling these other methods as well as providing a more unified way to change in the future how these common operations are performed. Custom calculation functions are passed an instance of the 'PivotCalculator' class, thereby also providing the authors of custom calculation functions an easy way for custom calculation functions to carry out common operations.
batchInfo
A summary of the batches used in evaluating the pivot table.
new()
Create a new 'PivotCalculator' object.
PivotCalculator$new(parentPivot = NULL)
parentPivot
The pivot table that this 'PivotCalculator' instance belongs to.
A new 'PivotCalculator' object.
getDataFrame()
Retrieve a data frame that was added to the pivot table.
PivotCalculator$getDataFrame(dataName = NULL)
dataName
The name of the data frame (as specified in 'pt$addData()') to retrieve.
The data frame with the specified name.
countTotalData()
Count the number of "totals" data frames that have been added to the pivot table.
PivotCalculator$countTotalData(dataName = NULL)
dataName
The name of the data frame (as specified in 'pt$addData()') that the "totals" data frames are associated with.
The number of "totals" data frames associated with the specified name.
getTotalDataFrame()
Retrieve a "totals" data frame that was added to the pivot table.
PivotCalculator$getTotalDataFrame(dataName = NULL, variableNames = NULL)
dataName
The name of the data frame (as specified in 'pt$addData()') that the "totals" data frame is associated with.
variableNames
The names of the variables that the totals are grouped by in the "totals" data frame (i.e. the dimensionality).
The "totals" data frame.
getCalculationGroup()
Retrieve a calculation group in the pivot table.
PivotCalculator$getCalculationGroup(calculationGroupName = NULL)
calculationGroupName
The name of the calculation group to retrieve.
The calculation group with the specified name.
getCalculation()
Retrieve a calculation in the pivot table.
PivotCalculator$getCalculation( calculationGroupName = NULL, calculationName = NULL )
calculationGroupName
The name of the calculation group to retrieve.
calculationName
The name of the calculation to retrieve.
The calculation with the specified name in the specified group.
generateBatchesForCellEvaluation()
Examine the data groups and cells in a pivot table to generate the structure of the batches in preparation for evaluating the pivot table.
PivotCalculator$generateBatchesForCellEvaluation()
The batches that exist in the pivot table.
evaluateBatches()
Execute the batch calculations as part of evaluating the pivot table.
PivotCalculator$evaluateBatches()
The number of batches that were evaluated.
newFilter()
Create a new 'PivotFilter' object associated with the specified data frame column name and column values. The new filter is conceptually of the form 'variableName
PivotCalculator$newFilter(variableName = NULL, values = NULL)
variableName
The data frame column name the filter is associated with.
values
The filter values for the filter.
The new 'PivotFilter' object.
newFilters()
Create a new 'PivotFilters' object associated with the specified data frame column name and column values. The new filter is conceptually of the form 'variableName
PivotCalculator$newFilters(variableName = NULL, values = NULL)
variableName
The data frame column name the filter is associated with.
values
The filter values for the filter.
A 'PivotFilters' object is a collection of 'PivotFilter' objects, therefore the return value of this method is suitable for use where other filters will subsequently be needed/applied.
The new 'PivotFilter' object.
setFilters()
Combines two 'PivotFilters' objects, e.g. to intersect the filters coming from the row and column headings for a particular cell.
PivotCalculator$setFilters( filters1 = NULL, filters2 = NULL, action = "replace" )
filters1
A 'PivotFilters' object.
filters2
A 'PivotFilters' object.
action
A character value specifying how to combine the two filters. Must be one of "intersect", "replace", "union".
A new 'PivotFilters' object.
setFilter()
Combines a 'PivotFilters' object with a 'PivotFilter' object.
PivotCalculator$setFilter(filters = NULL, filter = NULL, action = "replace")
filters
A 'PivotFilters' object.
filter
A 'PivotFilters' object.
action
A character value specifying how to combine the two filters. Must be one of "intersect", "replace", "union".
A new 'PivotFilters' object.
setFilterValues()
Combines a 'PivotFilters' object with additional filter criteria.
PivotCalculator$setFilterValues( filters = NULL, variableName = NULL, values = NULL, action = "replace" )
filters
A 'PivotFilters' object.
variableName
The name of the variable (i.e. column) in the data frame that the criteria relates to.
values
The values that the specified variable will be filtered to.
action
A character value specifying how to combine the existing filters and new filter criteria. Must be one of "intersect", "replace", "union".
A new 'PivotFilters' object.
getFilteredDataFrame()
Apply a set of filters to a data frame and return the filtered results.
PivotCalculator$getFilteredDataFrame(dataFrame = NULL, filters = NULL)
dataFrame
The data frame to filter.
filters
A 'PivotFilters' object containing the filter criteria.
dataName
The name of the data frame (as specified in 'pt$addData()') to be filtered.
A filtered data frame.
getDistinctValues()
Get the distinct values from a specified column in a data frame.
PivotCalculator$getDistinctValues(dataFrame = NULL, variableName = NULL)
dataFrame
The data frame.
variableName
The name of the variable to get the distinct values for.
A vector containing the distinct values.
formatValue()
Format a value using a variety of different methods.
PivotCalculator$formatValue(value = NULL, format = NULL, fmtFuncArgs = NULL)
value
The value to format.
format
Either a character format string to be used with 'sprintf()', a list of arguments to be used with 'base::format()' or a custom R function which will be invoked once per value to be formatted.
fmtFuncArgs
If 'format' is a custom R function, then 'fmtFuncArgs' specifies any additional arguments (in the form of a list) that will be passed to the custom function.
The formatted value if 'format' is specified, otherwise the 'value' converted to a character value.
getCombinedFilters()
Get the working filters for a calculation by combining row-column filters and calculation filters.
PivotCalculator$getCombinedFilters( rowColFilters = NULL, calcFilters = NULL, cell = NULL )
rowColFilters
A 'PivotFilters' object containing the combined filters from the row data groups and column data groups.
calcFilters
Either 'PivotFilters' object or a 'PivotFilterOverrides' object containing filers defined as part of the calculation.
cell
A 'PivotCell' object that is the cell for which the working data filters are being calculated.
A list of filters, element names: calculationFilters and workingFilters. The working filters are the row-column filters combined with the calculation filters.
getFiltersForNamedCalculation()
Get the working filters for a named calculation by calling 'getCombinedFilters()' as needed, depending on the calculation type.
PivotCalculator$getFiltersForNamedCalculation( calculationName = NULL, calculationGroupName = NULL, rowColFilters = NULL, cell = NULL )
calculationName
The name of the calculation.
calculationGroupName
The name of the calculation group.
rowColFilters
A 'PivotFilters' object containing the combined filters from the row data groups and column data groups.
cell
A 'PivotCell' object that is the cell for which the working data filters are being calculated.
A list of filters, where the element names are calculation names. Reminder: Evaluating a named calculation, if 'calc$type="calculation"', can involve computing multiple named calculations, which is why this return value is a list.
setWorkingData()
Set the working data filters for a cell in the pivot table.
PivotCalculator$setWorkingData(cell = NULL)
cell
The cell to generate the working data for.
The working data for a cell is a list of 'PivotFilters' objects - one per named calculation. Most cells only relate to one calculation, but calculations of type 'calc$type="calculation"' can relate to multiple calculations, hence the working data is a list where the element name is the calculation name. This method calls 'getFiltersForNamedCalculation()' internally to generate the filters for the working data.
No return value.
evaluateSingleValue()
Get a single value from a data frame, as part of evaluating a calculation where the calculation is of type 'calc$type="value"'.
PivotCalculator$evaluateSingleValue( dataFrame = NULL, workingFilters = NULL, valueName = NULL, format = NULL, fmtFuncArgs = NULL, noDataValue = NULL, noDataCaption = NULL )
dataFrame
The data frame to retrieve the value from.
workingFilters
The relevant working data for the calculation.
valueName
The name of the variable to retrieve from the data frame.
format
The formatting to apply to the value. See 'formatValue()' for details.
fmtFuncArgs
Additional arguments for a custom format function. See 'formatValue()' for details.
noDataValue
A replacement raw value to use if the value is NULL.
noDataCaption
A replacement formatted value to use if the value is NULL.
A list containing two elements: rawValue (typically numeric) and formattedValue (typically a character value).
evaluateSummariseExpression()
Get a summary value from a data frame, as part of evaluating a calculation where the calculation is of type 'calc$type="summary"'.
PivotCalculator$evaluateSummariseExpression( dataName = NULL, dataFrame = NULL, workingFilters = NULL, batchName = NULL, calculationName = NULL, calculationGroupName = NULL, summaryName = NULL, summariseExpression = NULL, format = NULL, fmtFuncArgs = NULL, noDataValue = NULL, noDataCaption = NULL )
dataName
The name of the data frame (as specified in 'pt$addData()') containing the data.
dataFrame
The data frame to retrieve the value from.
workingFilters
The relevant working data for the calculation.
batchName
The name of the batch that contains the results of the calculation (if batch evaluation is in use and possible for this cell and calculation).
calculationName
The name of the calculation.
calculationGroupName
The name of the calculation group.
summaryName
The name of the summary (typically also the calculation name).
summariseExpression
The dplyr or data.table expression to aggregate and summarise the data.
format
The formatting to apply to the value. See 'formatValue()' for details.
fmtFuncArgs
Additional arguments for a custom format function. See 'formatValue()' for details.
noDataValue
A replacement raw value to use if the value is NULL.
noDataCaption
A replacement formatted value to use if the value is NULL.
Where batch evaluation is used, the value is retrieved from the pre-calculated batch, otherwise dplyr/data.table is used to calculate the value (i.e. reverting to sequential evaluation mode which performs calculations cell-by-cell, one cell at a time).
A list containing two elements: rawValue (typically numeric) and formattedValue (typically a character value).
evaluateCalculationExpression()
Evaluates an R expression in order to combine the results of other calculations, as part of evaluating a calculation where the calculation is of type 'calc$type="calculation"'.
PivotCalculator$evaluateCalculationExpression( values = NULL, calculationExpression = NULL, format = NULL, fmtFuncArgs = NULL, noDataValue = NULL, noDataCaption = NULL )
values
The results of other calculations, passed in the form of a list where the element names are the names of those other calculations.
calculationExpression
A character expression to be evaluated, e.g. "values$TotalIncome/values$SaleCount".
format
The formatting to apply to the value. See 'formatValue()' for details.
fmtFuncArgs
Additional arguments for a custom format function. See 'formatValue()' for details.
noDataValue
A replacement raw value to use if the value is NULL.
noDataCaption
A replacement formatted value to use if the value is NULL.
A calculation, where 'calc$type="calculation"', combines the results of other calculations using a simple R expression.
A list containing two elements: rawValue (typically numeric) and formattedValue (typically a character value).
evaluateCalculateFunction()
Invokes a user-provided custom R function to aggregate data and perform calculations, as part of evaluating a calculation where the calculation is of type 'calc$type="function"'.
PivotCalculator$evaluateCalculateFunction( workingFilters = NULL, calculationFunction = NULL, calcFuncArgs = NULL, format = NULL, fmtFuncArgs = NULL, baseValues = NULL, cell = NULL )
workingFilters
The relevant working data for the calculation.
calculationFunction
The custom R function to invoke.
calcFuncArgs
Specifies any additional arguments (in the form of a list) that will be passed to the custom calculation function.
format
The formatting to apply to the value. See 'formatValue()' for details.
fmtFuncArgs
Additional arguments for a custom format function. See 'formatValue()' for details.
baseValues
The results of other calculations, passed in the form of a list where the element names are the names of those other calculations.
cell
A 'PivotCell' object representing the cell being calculated.
A calculation, where 'calc$type="function"', invokes a user provided R function on a cell-by-cell basis.
A list containing two elements: rawValue (typically numeric) and formattedValue (typically a character value).
evaluateNamedCalculationWD()
Invokes the relevant calculation function based upon the calculation type.
PivotCalculator$evaluateNamedCalculationWD( calculationName = NULL, calculationGroupName = NULL, workingData = NULL, cell = NULL )
calculationName
The name of the calculation to execute.
calculationGroupName
The calculation group that the calculation belongs to.
workingData
The relevant working data for the calculation.
cell
A 'PivotCell' object representing the cell being calculated.
This function examines the 'calc$type' property then invokes either 'evaluateSingleValue()', 'evaluateSummariseExpression()', 'evaluateCalculationExpression()' or 'evaluateCalculateFunction()'. Sometimes, more than one of the these functions is invoked, since calculation type "calculation" and "function" can/do make use of values from other calculations, which must be evaluated first.
A list containing two elements: rawValue (typically numeric) and formattedValue (typically a character value).
evaluateNamedCalculation()
Invokes the relevant calculation function based upon the calculation type.
PivotCalculator$evaluateNamedCalculation( calculationName = NULL, calculationGroupName = NULL, rowColFilters = NULL )
calculationName
The name of the calculation to execute.
calculationGroupName
The calculation group that the calculation belongs to.
rowColFilters
The filters arising from the row and column groups.
This function is a higher-level wrapper around 'evaluateNamedCalculationWD()'. This version incorporates logic to convert the filters from the row and column data groups into the working data filters, then calls 'evaluateNamedCalculationWD()'. This version has no suffix in the name, since this is the version users are more likely to invoke, e.g. from within a custom calculation function.
A list containing two elements: rawValue (typically numeric) and formattedValue (typically a character value).
evaluateCell()
Evaluate calculations to compute the value of a cell in a pivot table.
PivotCalculator$evaluateCell(cell = NULL)
cell
A 'PivotCell' object representing the cell to calculate.
A list containing two elements: rawValue (typically numeric) and formattedValue (typically a character value).
clone()
The objects of this class are cloneable with this method.
PivotCalculator$clone(deep = FALSE)
deep
Whether to make a deep clone.
# This class should only be created by the pivot table.
# It is not intended to be created outside of the pivot table.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.