| PivotCalculation {pivottabler} | R Documentation |
R6 class that defines a calculation.
Description
The 'PivotCalculation' class defines one calculation in a pivot table.
Format
R6Class object.
Active bindings
calculationNameCalculation unique name.
captionCalculation display name
visible'TRUE' to show the calculation in the pivot table or 'FALSE' to hide it. Hidden calculations are typically used as base values for other calculations.
displayOrderThe order the calculations are displayed in the pivot table.
filtersAny additional data filters specific to this calculation. This can be a 'PivotFilters' object that further restricts the data for the calculation or a list of individual 'PivotFilter' objects that provide more flexibility (and/or/replace). See the Calculations vignette for details.
formatA character, list or custom function to format the calculation result.
fmtFuncArgsA list that specifies any additional arguments to pass to a custom format function.
dataNameSpecifies which data frame in the pivot table is used for this calculation (as specified in 'pt$addData()').
typeThe calculation type: "summary", "calculation", "function" or "value".
valueNameFor type="value", the name of the column containing the value to display in the pivot table.
summariseExpressionFor type="summary", either the dplyr expression to use with dplyr::summarise() or a data.table calculation expression.
calculationExpressionFor type="calculation", an expression to combine aggregate values.
calculationFunctionFor type="function", a reference to a custom R function that will carry out the calculation.
calcFuncArgsFor type="function", a list that specifies additional arguments to pass to calculationFunction.
basedOnA character vector specifying the names of one or more calculations that this calculation depends on.
noDataValueAn integer or numeric value specifying the value to use if no data exists for a particular cell.
noDataCaptionA character value that will be displayed by the pivot table if no data exists for a particular cell.
headingBaseStyleNameThe name of a style defined in the pivot table to use as the base styling for the data group heading.
headingStyleDeclarationsA list of CSS style declarations (e.g. 'list("font-weight"="bold")') to override the base style.
cellBaseStyleNameThe name of a style defined in the pivot table to use as the base styling for the cells related to this calculation.
cellStyleDeclarationsA list of CSS style declarations (e.g. 'list("font-weight"="bold")') to override the base style.
Methods
Public methods
Method new()
Create a new 'PivotCalculation' object.
Usage
PivotCalculation$new( parentPivot, calculationName = NULL, caption = NULL, visible = TRUE, displayOrder = NULL, filters = NULL, format = NULL, fmtFuncArgs = NULL, dataName = NULL, type = "summary", valueName = NULL, summariseExpression = NULL, calculationExpression = NULL, calculationFunction = NULL, calcFuncArgs = NULL, basedOn = NULL, noDataValue = NULL, noDataCaption = NULL, headingBaseStyleName = NULL, headingStyleDeclarations = NULL, cellBaseStyleName = NULL, cellStyleDeclarations = NULL )
Arguments
parentPivotThe pivot table that this 'PivotCalculation' instance belongs to.
calculationNameCalculation unique name.
captionCalculation display name
visible'TRUE' to show the calculation in the pivot table or 'FALSE' to hide it. Hidden calculations are typically used as base values for other calculations.
displayOrderThe order the calculations are displayed in the pivot table.
filtersAny additional data filters specific to this calculation. This can be a 'PivotFilters' object that further restricts the data for the calculation or a list of individual 'PivotFilter' objects that provide more flexibility (and/or/replace). See the Calculations vignette for details.
formatA character, list or custom function to format the calculation result.
fmtFuncArgsA list that specifies any additional arguments to pass to a custom format function.
dataNameSpecifies which data frame in the pivot table is used for this calculation (as specified in 'pt$addData()').
typeThe calculation type: "summary", "calculation", "function" or "value".
valueNameFor type="value", the name of the column containing the value to display in the pivot table.
summariseExpressionFor type="summary", either the dplyr expression to use with dplyr::summarise() or a data.table calculation expression.
calculationExpressionFor type="calculation", an expression to combine aggregate values.
calculationFunctionFor type="function", a reference to a custom R function that will carry out the calculation.
calcFuncArgsFor type="function", a list that specifies additional arguments to pass to calculationFunction.
basedOnA character vector specifying the names of one or more calculations that this calculation depends on.
noDataValueAn integer or numeric value specifying the value to use if no data exists for a particular cell.
noDataCaptionA character value that will be displayed by the pivot table if no data exists for a particular cell.
headingBaseStyleNameThe name of a style defined in the pivot table to use as the base styling for the data group heading.
headingStyleDeclarationsA list of CSS style declarations (e.g. 'list("font-weight"="bold")') to override the base style.
cellBaseStyleNameThe name of a style defined in the pivot table to use as the base styling for the cells related to this calculation.
cellStyleDeclarationsA list of CSS style declarations (e.g. 'list("font-weight"="bold")') to override the base style.
Returns
A new 'PivotCalculation' object.
Method asList()
Return the contents of this object as a list for debugging.
Usage
PivotCalculation$asList()
Returns
A list of various object properties.
Method asJSON()
Return the contents of this object as JSON for debugging.
Usage
PivotCalculation$asJSON()
Returns
A JSON representation of various object properties.
Method asString()
Return a representation of this object as a character value.
Usage
PivotCalculation$asString()
Returns
A character summary of various object properties.
Method clone()
The objects of this class are cloneable with this method.
Usage
PivotCalculation$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Examples
# This class should only be created by the pivot table.
# It is not intended to be created outside of the pivot table.