The `PivotDataGroup` class represents one row or column heading in a pivot table. Data groups exist in a hierarchy and have a parent-child relationship, i.e. each `PivotDataGroup` instance can have one or more child data groups.
R6Class object.
instanceIdAn integer value that uniquely identifies this group. NB: This number is guaranteed to be unique within the pivot table, but the method of generation of the values may change in future, so you are advised not to base any logic on specific values.
rowOrColumnEither "row" or "column"
parentGroupThe parent `PivotDataGroup` instance that this `PivotDataGroup` instance belongs to.
childGroupsA list of `PivotDataGroup` objects that are the children of this data group.
childGroupCountA count of `PivotDataGroup` objects that are the children of this data group.
leafGroupsA list of `PivotDataGroup` objects that are leaf-level descendants of this data group.
levelNumberAn integer value specifying the level number where this data group exists in the hierarchy.
filtersA `PivotFilters` object containing the filters associated with this data group.
variableNameA character value that specifies the name of the variable in the data frame that this group relates to and will filter.
valuesA vector that specifies the filter values applied to `variableName` to select the data to match this row/column in the pivot table.
calculationGroupNameFor calculation groups, this character value specifies the calculation group that `calculationName` belongs to.
calculationNameFor calculation groups, this character value specifies the name of the calculation.
doNotExpand`TRUE` if this data group prevent the high-level methods such as `addDataGroups()` from adding child groups.
isEmpty`TRUE` if this group contains no data (e.g. if it is part of a header or outline row)
isOutline`TRUE` if this data group is an outline group.
styleAsOutline`TRUE` if this data group is to be styled as an outline group. Only applicable when `isOutline` is `TRUE`.
outlineLinkedGroupIdThe instance id of the child group related to this group, if this group is an outline group.
outlineLinkedGroupExists`TRUE` if the group specified by `outlineLinkedGroupId` still exists.
captionTemplateA character value that specifies the template for the data group caption, default "values".
captionThe data group caption. Assigning a caption effectively overrides the built-in logic for generating a caption.
sortValueThe raw (i.e. unformatted, typically numerical) value that represents this data group in sort operations.
isTotal`TRUE` if this data group is a total.
isLevelSubTotal`TRUE` if this data group is a sub-total.
isLevelTotal`TRUE` if this data group is a level-total.
rowColumnNumberThe row or column number that this data group relates to. This property only has a value for leaf-level data groups.
baseStyleNameThe style name for the data group.
styleA `PivotStyle` object that contains additional CSS style declarations that override the base style.
mergeEmptySpaceA logical value that specifies whether empty space should be merged.
cellBaseStyleNameThe style name for cells related to this data group.
netCellBaseStyleNameThe style name for cells related to this data group - either from this group or the first ancestor that specifies a cellBaseStyleName if cellBaseStyleName is not specified on this group.
cellStyleA `PivotStyle` object that contains additional CSS style declarations that override the base style for cells related to this data group. If setting this property, a list can also be specified.
netCellStyleA `PivotStyle` object that contains additional CSS style declarations that override the base style for cells related to this data group - both from this group and all ancestors.
fixedWidthSizeThe width (in characters) needed for this data group when rendering to plain text.
isMatchAn internal property used when finding data groups.
isRenderedAn internal property used when rendering data groups.
isWithinVisibleRangeAn internal property used when rendering data groups.
visibleChildGroupCountAn internal property used when rendering data groups.
visibleDescendantGroupCountAn internal property used when rendering data groups.
visibleLeafGroupCountAn internal property used when rendering data groups.
sortAnchorUsed to specify sort behaviour for outline groups, must be one of "fixed", "next" or "previous".
sortGroupsBeforeAn internal property used when sorting data groups.
sortGroupsAfterAn internal property used when sorting data groups.
new()Create a new `PivotDataGroup` object.
PivotDataGroup$new(
parentGroup = NULL,
parentPivot = NULL,
rowOrColumn = NULL,
doNotExpand = FALSE,
isEmpty = FALSE,
isOutline = FALSE,
styleAsOutline = FALSE,
captionTemplate = "{value}",
caption = NULL,
isTotal = FALSE,
isLevelSubTotal = FALSE,
isLevelTotal = FALSE,
variableName = NULL,
filterType = "ALL",
values = NULL,
calculationGroupName = NULL,
calculationName = NULL,
baseStyleName = NULL,
styleDeclarations = NULL,
mergeEmptySpace = NULL,
cellBaseStyleName = NULL,
cellStyleDeclarations = NULL,
sortAnchor = NULL,
outlineLinkedGroupId = NULL
)parentGroupThe parent `PivotDataGroup` instance that this `PivotDataGroup` instance belongs to.
parentPivotThe pivot table that this `PivotDataGroup` instance belongs to.
rowOrColumnEither "row" or "column" indicating which axis this data group exists on.
doNotExpandDefault value `FALSE` - specify `TRUE` to prevent the high-level methods such as `addDataGroups()` from adding child groups.
isEmptyDefault value `FALSE`, specify `TRUE` to mark that this group contains no data (e.g. if it is part of a header or outline row)
isOutlineDefault value `FALSE` - specify `TRUE` to mark that this data group is an outline group.
styleAsOutlineDefault value `FALSE` - specify `TRUE` to style this data group as an outline group. Only applicable when `isOutline` is `TRUE`.
captionTemplateA character value that specifies the template for the data group caption, default "values".
captionEffectively a hard-coded caption that overrides the built-in logic for generating a caption.
isTotalDefault `FALSE` - specify `TRUE` to mark that this data group is a total.
isLevelSubTotalDefault `FALSE` - specify `TRUE` to mark that this data group is a sub-total within a level.
isLevelTotalDefault `FALSE` - specify `TRUE` to mark that this data group is level total.
variableNameA character value that specifies the name of the variable in the data frame that the group relates to and will filter.
filterTypeMust be one of "ALL", "VALUES", or "NONE" to specify the filter type: ALL means no filtering is applied. VALUEs is the typical value used to specify that `variableName` is filtered to only `values`. NONE means no data will match this data group.
valuesA vector that specifies the filter values applied to `variableName` to select the data to match this row/column in the pivot table.
calculationGroupNameFor calculation groups, this character value specifies the calculation group that `calculationName` belongs to.
calculationNameFor calculation groups, this character value specifies the name of the calculation.
baseStyleNameThe style name for the data group.
styleDeclarationsA list of CSS style declarations to overlay on top of the base style.
mergeEmptySpaceA character value that specifies how empty space should be merged. This is typically only used with outline groups (so applies to row groups only, not column groups). Must be one of "doNotMerge", "dataGroupsOnly", "cellsOnly", "dataGroupsAndCellsAs1" or "dataGroupsAndCellsAs2". See the "Regular Layout" vignette for more information.
cellBaseStyleNameThe style name for cells related to this data group.
cellStyleDeclarationsA list of CSS style declarations to overlay on top of the base style for cells related to this data group
sortAnchorUsed to specify sort behaviour for outline groups, must be one of "fixed", "next" or "previous".
outlineLinkedGroupIdUsed to link an outline group to the value data group which has the child data groups.
getLevelNumber()Retrieve the level number in the hierarchy that the current data group exists at.
getAncestorGroups()Get all of the data groups above the current data group in the parent-child data group hierarchy.
getDescendantGroups()Get all of the data groups below the current data group in the parent-child data group hierarchy.
getLeafGroups()Get all of the data groups below the current data group in the parent-child data group hierarchy.
getLevelCount()Count the number of levels in the data group hierarchy.
getLevelGroups()Retrieve all of the data groups at a specific level in the data group hierarchy.
getRelatedOutlineGroups()Retrieve the a list of the typically two or three related data groups that were created as one outlined group.
getChildIndex()Get the index of a child group (or groups) in the current groups list of child groups.
findChildIndex()Find the index of a child group (or groups) corresponding to the specified instance id(s) in the current groups list of child groups.
addChildGroup()Add a new data group as a child of the current data group. The new group is added as the last child unless an index is specified.
PivotDataGroup$addChildGroup(
variableName = NULL,
filterType = "ALL",
values = NULL,
doNotExpand = FALSE,
isEmpty = FALSE,
isOutline = FALSE,
styleAsOutline = FALSE,
captionTemplate = "{value}",
caption = NULL,
isTotal = FALSE,
isLevelSubTotal = FALSE,
isLevelTotal = FALSE,
calculationGroupName = NULL,
calculationName = NULL,
baseStyleName = NULL,
styleDeclarations = NULL,
insertAtIndex = NULL,
insertBeforeGroup = NULL,
insertAfterGroup = NULL,
mergeEmptySpace = NULL,
cellBaseStyleName = NULL,
cellStyleDeclarations = NULL,
sortAnchor = NULL,
outlineLinkedGroupId = NULL,
resetCells = TRUE
)variableNameA character value that specifies the name of the variable in the data frame that the group relates to and will filter.
filterTypeMust be one of "ALL", "VALUES", or "NONE" to specify
the filter type:
ALL means no filtering is applied.
VALUEs is the typical value used to specify that `variableName` is
filtered to only `values`.
NONE means no data will match this data group.
valuesA vector that specifies the filter values applied to `variableName` to select the data to match this row/column in the pivot table.
doNotExpandDefault value `FALSE` - specify `TRUE` to prevent the high-level methods such as `addDataGroups()` from adding child groups.
isEmptyDefault value `FALSE`, specify `TRUE` to mark that this group contains no data (e.g. if it is part of a header or outline row)
isOutlineDefault value `FALSE` - specify `TRUE` to mark that this data group is an outline group.
styleAsOutlineDefault value `FALSE` - specify `TRUE` to style this data group as an outline group. Only applicable when `isOutline` is `TRUE`.
captionTemplateA character value that specifies the template for the data group caption, default "values".
captionEffectively a hard-coded caption that overrides the built-in logic for generating a caption.
isTotalDefault `FALSE` - specify `TRUE` to mark that this data group is a total.
isLevelSubTotalDefault `FALSE` - specify `TRUE` to mark that this data group is a sub-total within a level.
isLevelTotalDefault `FALSE` - specify `TRUE` to mark that this data group is level total.
calculationGroupNameFor calculation groups, this character value specifies the calculation group that `calculationName` belongs to.
calculationNameFor calculation groups, this character value specifies the name of the calculation.
baseStyleNameThe style name for the data group.
styleDeclarationsA list of CSS style declarations to overlay on top of the base style.
insertAtIndexAn integer that specifies the index in the list of child groups where the new group should be inserted.
insertBeforeGroupSpecifies an existing group that the new group should be inserted before.
insertAfterGroupSpecifies an existing group that the new group should be inserted after
mergeEmptySpaceA character value that specifies how empty space should be merged. This is typically only used with outline groups (so applies to row groups only, not column groups). Must be one of "doNotMerge", "dataGroupsOnly", "cellsOnly", "dataGroupsAndCellsAs1" or "dataGroupsAndCellsAs2". See the "Regular Layout" vignette for more information.
cellBaseStyleNameThe style name for cells related to this data group.
cellStyleDeclarationsA list of CSS style declarations to overlay on top of the base style for cells related to this data group
sortAnchorUsed to specify sort behaviour for outline groups, must be one of "fixed", "next" or "previous".
outlineLinkedGroupIdUsed to link an outline group to the value data group which has the child data groups.
resetCellsDefault `TRUE` to reset any cells that currently exist in the pivot table and trigger a recalculation of the pivot table when it is next rendered.
removeChildGroup()Remove a data group that is a child of the current data group.
indexAn index that specifies the location of the group to remove in the list of child groups.
groupA `PivotDataGroup` object to be removed. Only one of `index` or `group` needs to be specified.
resetCellsDefault `TRUE` to reset any cells that currently exist in the pivot table and trigger a recalculation of the pivot table when it is next rendered.
removeGroup()Remove the current data group.
PivotDataGroup$removeGroup(
removeAncestorsIfNoRemainingChildren = FALSE,
removedRelatedOutlineGroups = FALSE,
resetCells = TRUE
)removeAncestorsIfNoRemainingChildrenDefault `FALSE` - specify `TRUE` to recursively remove ancestor groups if they have no remaining child groups.
removedRelatedOutlineGroupsDefault `FALSE` - specify `TRUE` to remove related outline groups.
resetCellsDefault `TRUE` to reset any cells that currently exist in the pivot table and trigger a recalculation of the pivot table when it is next rendered.
addDataGroups()Add multiple new data groups based on the distinct values in a data frame column or using explicitly specified data values. See the "Irregular Layout" vignette for example usage.
PivotDataGroup$addDataGroups(
variableName = NULL,
atLevel = NULL,
fromData = TRUE,
dataName = NULL,
dataSortOrder = "asc",
customSortOrder = NULL,
caption = "{value}",
dataFormat = NULL,
dataFmtFuncArgs = NULL,
onlyCombinationsThatExist = TRUE,
explicitListOfValues = NULL,
calculationGroupName = NULL,
expandExistingTotals = FALSE,
addTotal = TRUE,
visualTotals = FALSE,
totalPosition = "after",
totalCaption = "Total",
onlyAddGroupIf = NULL,
preGroupData = TRUE,
baseStyleName = NULL,
styleDeclarations = NULL,
outlineBefore = NULL,
outlineAfter = NULL,
outlineTotal = FALSE,
onlyAddOutlineChildGroupIf = NULL
)variableNameThe name of the related column in the data frame(s) of the pivot table.
atLevelThe number of levels below the current group to add the new groups. 0 = at the current level, 1 = one level below the current group, etc. `NULL` = create a new level at the bottom of the hierarchy for the new groups.
fromDataDefault `TRUE` to generate the new data groups based on the data values that exist in the `variableName` column in the named data frame. If `FALSE`, then `explicitListOfValues` must be specified.
dataNameThe name of the data frame (as specified in `pt$addData()`) to read the data group values from.
dataSortOrderMust be one of "asc", "desc", "custom" or "none".
customSortOrderA vector values sorted into the desired order.
captionThe template of data group captions to generate, default "value".
dataFormatA character, list or custom function to format the data value.
dataFmtFuncArgsA list that specifies any additional arguments to pass to a custom format function.
onlyCombinationsThatExistDefault `TRUE` to generate only combinations of data groups that exist in the data frame.
explicitListOfValuesA list of explicit values to create data groups from. A data group is created for each element of the list. If a list element is vector of values (with length greater than 1), then a data group is created for multiple values instead of just a single value.
calculationGroupNameThe calculation group that the new data groups are related to.
expandExistingTotalsDefault `FALSE`, which means totals are not broken down in multi-level hierarchies.
addTotalDefault `TRUE`, which means sub-total and total data groups are automatically added.
visualTotalsDefault `FALSE`, which means visual totals are disabled. See the "Data Groups" vignette for more details about visual totals.
totalPositionEither "before" or "after" to specify where total groups are created, default "after".
totalCaptionThe caption to display on total groups, default "Total".
onlyAddGroupIfA filter expression that can be used to more finely control whether data groups are created at different locations in the hierarchy. There must be at least one row that matches this filter and the filters from the ancestor groups in order that the child group is created. E.g. `MaxDisplayLevel>5`.
preGroupDataDefault `TRUE`, which means that the pivot table pre-calculates the distinct combinations of variable values to reduce the CPU time and elapsed time required to generate data groups. Cannot be used in conjunction with the
baseStyleNameThe name of the style applied to this data group (i.e. this row/column heading). The style must exist in the `PivotStyles` object associated with the PivotTable.
styleDeclarationsCSS style declarations that can override the base style, expressed as a list, e.g. `list("font-weight"=bold")`.
outlineBeforeDefault `FALSE` to disable the creation of outline header groups. Specify either `TRUE` or a list of outline group settings to create outline header groups. See the "Regular Layout" vignette for details.
outlineAfterDefault `FALSE` to disable the creation of outline footer groups. Specify either `TRUE` or a list of outline group settings to create outline footer groups. See the "Regular Layout" vignette for details.
outlineTotalDefault `FALSE` to disable the creation of outline totals. Specify either `TRUE` or a list of outline group settings to create outline totals. See the "Regular Layout" vignette for details.
onlyAddOutlineChildGroupIfA filter expression that can be used to more finely control whether outline child groups are created at different locations in the hierarchy. There must be at least one row that matches this filter and the filters from the ancestor groups in order that the outline child group is created. E.g. `MaxDisplayLevel>5`. See the "Regular Layout" vignette for an example.
There are broadly three different ways to call `addDataGroups()`:
(1) dataName=name, fromData=TRUE, onlyCombinationsThatExist=TRUE - which
considers the ancestors of each existing data group to generate only those
combinations of values that exist in the data frame.
(2) dataName=name, fromData=TRUE, onlyCombinationsThatExist=FALSE - which
ignores the ancestors of each existing data group and simply adds every
distinct value of the specified variable under every existing data group,
which can result in combinations of values in the pivot table that don't
exist in the data frame (i.e. blank rows/columns in the pivot table).
(3) fromData=FALSE, explicitListOfValues=list(...) - simply adds every
value from the specified list under every existing data group.
sortDataGroups()Sort data groups either by the data group data value, caption, a custom order or based on calculation result values.
PivotDataGroup$sortDataGroups(
levelNumber = 1,
orderBy = "calculation",
customOrder = NULL,
sortOrder = "desc",
calculationGroupName = "default",
calculationName = NULL,
fromIndex = NULL,
toIndex = NULL,
resetCells = TRUE
)levelNumberThe number of levels below the current group to sort the data groups. 0 = at the current level, 1 = one level below the current group, etc.
orderByMust be either "value", "caption", "calculation",
"customByValue" or "customByCaption".
"value" sorts by the raw (i.e. unformatted) group value.
"caption" sorts by the formatted character group caption.
"calculation" sorts using one of the calculations defined in the pivot table.
"customValue" sorts by the raw (i.e. unformatted) group value according to
the specified custom sort order.
"customCaption" sorts by the formatted character group caption according to
the specified custom sort order.
customOrderA vector values sorted into the desired order.
sortOrderMust be either "asc" or "desc".
calculationGroupNameIf sorting using a calculation, the name of the calculation group containing the specified calculation.
calculationNameIf sorting using a calculation, the name of the calculation.
fromIndexA boundary to limit the sort operation.
toIndexA boundary to limit the sort operation.
resetCellsDefault `TRUE` to reset any cells that currently exist in the pivot table and trigger a recalculation of the pivot table when it is next rendered.
addCalculationGroups()Add multiple new groups to the data group hierarchy to represent calculations.
PivotDataGroup$addCalculationGroups(
calculationGroupName = NULL,
atLevel = NULL,
outlineBefore = NULL,
outlineAfter = NULL,
resetCells = TRUE
)calculationGroupNameThe name of the calculation group to add into the data group hierarchy.
atLevelThe number of levels below the current group to add the new groups. 0 = at the current level, 1 = one level below the current group, etc. `NULL` = create a new level at the bottom of the hierarchy for the new groups.
outlineBeforeDefault `FALSE` to disable the creation of outline header groups. Specify either `TRUE` or a list of outline group settings to create outline header groups. See the "Regular Layout" vignette for details.
outlineAfterDefault `FALSE` to disable the creation of outline footer groups. Specify either `TRUE` or a list of outline group settings to create outline footer groups. See the "Regular Layout" vignette for details.
resetCellsDefault `TRUE` to reset any cells that currently exist in the pivot table and trigger a recalculation of the pivot table when it is next rendered.
normaliseDataGroup()Normalise the data group hierarchy so that all branches have the same number of levels - accomplished by adding empty child data groups where needed.
getNetFilters()Get a `PivotFilters` object that contains the filters applied in this data group and all of its ancestors in the data group hierarchy.
getNetCalculationName()Get the calculation name set in this data group or its nearest ancestor.
isFindMatch()Test whether this data group matches specified criteria.
PivotDataGroup$isFindMatch(
matchMode = "simple",
variableNames = NULL,
variableValues = NULL,
totals = "include",
calculationNames = NULL,
atLevels = NULL,
minChildCount = NULL,
maxChildCount = NULL,
emptyGroups = "exclude",
outlineGroups = "exclude",
outlineLinkedGroupExists = NULL
)matchModeEither "simple" (default) or "combinations".
"simple" is used when matching only one variable-value, multiple
variable-value combinations are effectively logical "OR".
"combinations" is used when matching for combinations of variable
values, multiple variable-value combinations are effectively
logical "AND". A child group is viewed as having the variable-value
filters of itself and it's parent/ancestors, e.g.
`list("TrainCategory"="Express Passenger", "PowerType"="DMU")`,
would return the "DMU" data group underneath "Express Passenger".
See the "Finding and Formatting" vignette for graphical examples.
variableNamesA character vector specifying the name/names of the variables to find. This is useful generally only in pivot tables with irregular layouts, since in regular pivot tables every cell is related to every variable.
variableValuesA list specifying the variable names and values to find,
e.g. `variableValues=list("PowerType"=c("DMU", "HST"))`.
Specify "**" as the variable value to match totals for the specified variable.
Specify "!*" as the variable value to match non-totals for the specified variable.
NB: The totals/non-totals criteria above won’t work when visual totals are used.
totalsA word that specifies how totals are matched (overrides the finer settings above) - must be one of "include" (default), "exclude" or "only".
calculationNamesA character vector specifying the name/names of the calculations to find.
atLevelsAn integer vector constraining the levels in the hierarchy to search.
minChildCountMatch only data groups with this minimum number of children.
maxChildCountMatch only data groups with this maximum number of children.
emptyGroupsA word that specifies how empty groups are matched - must be one of "include", "exclude" (default) or "only".
outlineGroupsA word that specifies how outline cells are matched - must be one of "include", "exclude" (default) or "only".
outlineLinkedGroupExists`TRUE` to match only groups where the related outline child group still exists. `FALSE` to match only groups where the related outline child group no longer exists.
findDataGroups()Find data groups that match specified criteria.
PivotDataGroup$findDataGroups(
matchMode = "simple",
variableNames = NULL,
variableValues = NULL,
totals = "include",
calculationNames = NULL,
atLevels = NULL,
minChildCount = NULL,
maxChildCount = NULL,
emptyGroups = "exclude",
outlineGroups = "exclude",
outlineLinkedGroupExists = NULL,
includeDescendantGroups = FALSE,
includeCurrentGroup = TRUE
)matchModeEither "simple" (default) or "combinations".
"simple" is used when matching only one variable-value, multiple
variable-value combinations are effectively logical "OR".
"combinations" is used when matching for combinations of variable
values, multiple variable-value combinations are effectively
logical "AND". A child group is viewed as having the variable-value
filters of itself and it's parent/ancestors, e.g.
`list("TrainCategory"="Express Passenger", "PowerType"="DMU")`,
would return the "DMU" data group underneath "Express Passenger".
See the "Finding and Formatting" vignette for graphical examples.
variableNamesA character vector specifying the name/names of the variables to find. This is useful generally only in pivot tables with irregular layouts, since in regular pivot tables every cell is related to every variable.
variableValuesA list specifying the variable names and values to find,
e.g. `variableValues=list("PowerType"=c("DMU", "HST"))`.
Specify "**" as the variable value to match totals for the specified variable.
Specify "!*" as the variable value to match non-totals for the specified variable.
NB: The totals/non-totals criteria above won’t work when visual totals are used.
totalsA word that specifies how totals are matched (overrides the finer settings above) - must be one of "include" (default), "exclude" or "only".
calculationNamesA character vector specifying the name/names of the calculations to find.
atLevelsAn integer vector constraining the levels in the hierarchy to search.
minChildCountMatch only data groups with this minimum number of children.
maxChildCountMatch only data groups with this maximum number of children.
emptyGroupsA word that specifies how empty groups are matched - must be one of "include", "exclude" (default) or "only".
outlineGroupsA word that specifies how outline cells are matched - must be one of "include", "exclude" (default) or "only".
outlineLinkedGroupExists`TRUE` to match only groups where the related outline child group still exists. `FALSE` to match only groups where the related outline child group no longer exists.
includeDescendantGroupsDefault `FALSE`. Specify true to also return all descendants of data groups that match the specified criteria.
includeCurrentGroupDefault `TRUE`. Specify `FALSE` to prevent the current group being included in the returned results.
setStyling()An internal method used to set style declarations on the data group. Using `pt$setStyling(cells=x)` is preferred for users.
# This class should only be created by the pivot table.
# It is not intended to be created outside of the pivot table.