| 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.
batchInfoA summary of the batches used in evaluating the pivot table.
new()Create a new 'PivotCalculator' object.
PivotCalculator$new(parentPivot = NULL)
parentPivotThe 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)
dataNameThe 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)
dataNameThe 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)
dataNameThe name of the data frame (as specified in 'pt$addData()') that the "totals" data frame is associated with.
variableNamesThe 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)
calculationGroupNameThe 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 )
calculationGroupNameThe name of the calculation group to retrieve.
calculationNameThe 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)
variableNameThe data frame column name the filter is associated with.
valuesThe 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)
variableNameThe data frame column name the filter is associated with.
valuesThe 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" )
filters1A 'PivotFilters' object.
filters2A 'PivotFilters' object.
actionA 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")
filtersA 'PivotFilters' object.
filterA 'PivotFilters' object.
actionA 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" )
filtersA 'PivotFilters' object.
variableNameThe name of the variable (i.e. column) in the data frame that the criteria relates to.
valuesThe values that the specified variable will be filtered to.
actionA 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)
dataFrameThe data frame to filter.
filtersA 'PivotFilters' object containing the filter criteria.
dataNameThe 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)
dataFrameThe data frame.
variableNameThe 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)
valueThe value to format.
formatEither 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.
fmtFuncArgsIf '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 )
rowColFiltersA 'PivotFilters' object containing the combined filters from the row data groups and column data groups.
calcFiltersEither 'PivotFilters' object or a 'PivotFilterOverrides' object containing filers defined as part of the calculation.
cellA '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 )
calculationNameThe name of the calculation.
calculationGroupNameThe name of the calculation group.
rowColFiltersA 'PivotFilters' object containing the combined filters from the row data groups and column data groups.
cellA '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)
cellThe 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 )
dataFrameThe data frame to retrieve the value from.
workingFiltersThe relevant working data for the calculation.
valueNameThe name of the variable to retrieve from the data frame.
formatThe formatting to apply to the value. See 'formatValue()' for details.
fmtFuncArgsAdditional arguments for a custom format function. See 'formatValue()' for details.
noDataValueA replacement raw value to use if the value is NULL.
noDataCaptionA 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 )
dataNameThe name of the data frame (as specified in 'pt$addData()') containing the data.
dataFrameThe data frame to retrieve the value from.
workingFiltersThe relevant working data for the calculation.
batchNameThe name of the batch that contains the results of the calculation (if batch evaluation is in use and possible for this cell and calculation).
calculationNameThe name of the calculation.
calculationGroupNameThe name of the calculation group.
summaryNameThe name of the summary (typically also the calculation name).
summariseExpressionThe dplyr or data.table expression to aggregate and summarise the data.
formatThe formatting to apply to the value. See 'formatValue()' for details.
fmtFuncArgsAdditional arguments for a custom format function. See 'formatValue()' for details.
noDataValueA replacement raw value to use if the value is NULL.
noDataCaptionA 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 )
valuesThe results of other calculations, passed in the form of a list where the element names are the names of those other calculations.
calculationExpressionA character expression to be evaluated, e.g. "values$TotalIncome/values$SaleCount".
formatThe formatting to apply to the value. See 'formatValue()' for details.
fmtFuncArgsAdditional arguments for a custom format function. See 'formatValue()' for details.
noDataValueA replacement raw value to use if the value is NULL.
noDataCaptionA 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 )
workingFiltersThe relevant working data for the calculation.
calculationFunctionThe custom R function to invoke.
calcFuncArgsSpecifies any additional arguments (in the form of a list) that will be passed to the custom calculation function.
formatThe formatting to apply to the value. See 'formatValue()' for details.
fmtFuncArgsAdditional arguments for a custom format function. See 'formatValue()' for details.
baseValuesThe results of other calculations, passed in the form of a list where the element names are the names of those other calculations.
cellA '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 )
calculationNameThe name of the calculation to execute.
calculationGroupNameThe calculation group that the calculation belongs to.
workingDataThe relevant working data for the calculation.
cellA '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 )
calculationNameThe name of the calculation to execute.
calculationGroupNameThe calculation group that the calculation belongs to.
rowColFiltersThe 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)
cellA '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)
deepWhether 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.