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.
instanceId
An 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.
rowOrColumn
Either "row" or "column"
parentGroup
The parent `PivotDataGroup` instance that this `PivotDataGroup` instance belongs to.
childGroups
A list of `PivotDataGroup` objects that are the children of this data group.
childGroupCount
A count of `PivotDataGroup` objects that are the children of this data group.
leafGroups
A list of `PivotDataGroup` objects that are leaf-level descendants of this data group.
levelNumber
An integer value specifying the level number where this data group exists in the hierarchy.
filters
A `PivotFilters` object containing the filters associated with this data group.
variableName
A character value that specifies the name of the variable in the data frame that this group relates to and will filter.
values
A vector that specifies the filter values applied to `variableName` to select the data to match this row/column in the pivot table.
calculationGroupName
For calculation groups, this character value specifies the calculation group that `calculationName` belongs to.
calculationName
For 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`.
outlineLinkedGroupId
The 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.
captionTemplate
A character value that specifies the template for the data group caption, default "values".
caption
The data group caption. Assigning a caption effectively overrides the built-in logic for generating a caption.
sortValue
The 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.
rowColumnNumber
The row or column number that this data group relates to. This property only has a value for leaf-level data groups.
baseStyleName
The style name for the data group.
style
A `PivotStyle` object that contains additional CSS style declarations that override the base style.
mergeEmptySpace
A logical value that specifies whether empty space should be merged.
cellBaseStyleName
The style name for cells related to this data group.
netCellBaseStyleName
The 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.
cellStyle
A `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.
netCellStyle
A `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.
fixedWidthSize
The width (in characters) needed for this data group when rendering to plain text.
isMatch
An internal property used when finding data groups.
isRendered
An internal property used when rendering data groups.
isWithinVisibleRange
An internal property used when rendering data groups.
visibleChildGroupCount
An internal property used when rendering data groups.
visibleDescendantGroupCount
An internal property used when rendering data groups.
visibleLeafGroupCount
An internal property used when rendering data groups.
sortAnchor
Used to specify sort behaviour for outline groups, must be one of "fixed", "next" or "previous".
sortGroupsBefore
An internal property used when sorting data groups.
sortGroupsAfter
An 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
)
parentGroup
The parent `PivotDataGroup` instance that this `PivotDataGroup` instance belongs to.
parentPivot
The pivot table that this `PivotDataGroup` instance belongs to.
rowOrColumn
Either "row" or "column" indicating which axis this data group exists on.
doNotExpand
Default value `FALSE` - specify `TRUE` to prevent the high-level methods such as `addDataGroups()` from adding child groups.
isEmpty
Default value `FALSE`, specify `TRUE` to mark that this group contains no data (e.g. if it is part of a header or outline row)
isOutline
Default value `FALSE` - specify `TRUE` to mark that this data group is an outline group.
styleAsOutline
Default value `FALSE` - specify `TRUE` to style this data group as an outline group. Only applicable when `isOutline` is `TRUE`.
captionTemplate
A character value that specifies the template for the data group caption, default "values".
caption
Effectively a hard-coded caption that overrides the built-in logic for generating a caption.
isTotal
Default `FALSE` - specify `TRUE` to mark that this data group is a total.
isLevelSubTotal
Default `FALSE` - specify `TRUE` to mark that this data group is a sub-total within a level.
isLevelTotal
Default `FALSE` - specify `TRUE` to mark that this data group is level total.
variableName
A character value that specifies the name of the variable in the data frame that the group relates to and will filter.
filterType
Must 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.
values
A vector that specifies the filter values applied to `variableName` to select the data to match this row/column in the pivot table.
calculationGroupName
For calculation groups, this character value specifies the calculation group that `calculationName` belongs to.
calculationName
For calculation groups, this character value specifies the name of the calculation.
baseStyleName
The style name for the data group.
styleDeclarations
A list of CSS style declarations to overlay on top of the base style.
mergeEmptySpace
A 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.
cellBaseStyleName
The style name for cells related to this data group.
cellStyleDeclarations
A list of CSS style declarations to overlay on top of the base style for cells related to this data group
sortAnchor
Used to specify sort behaviour for outline groups, must be one of "fixed", "next" or "previous".
outlineLinkedGroupId
Used 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
)
variableName
A character value that specifies the name of the variable in the data frame that the group relates to and will filter.
filterType
Must 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.
values
A vector that specifies the filter values applied to `variableName` to select the data to match this row/column in the pivot table.
doNotExpand
Default value `FALSE` - specify `TRUE` to prevent the high-level methods such as `addDataGroups()` from adding child groups.
isEmpty
Default value `FALSE`, specify `TRUE` to mark that this group contains no data (e.g. if it is part of a header or outline row)
isOutline
Default value `FALSE` - specify `TRUE` to mark that this data group is an outline group.
styleAsOutline
Default value `FALSE` - specify `TRUE` to style this data group as an outline group. Only applicable when `isOutline` is `TRUE`.
captionTemplate
A character value that specifies the template for the data group caption, default "values".
caption
Effectively a hard-coded caption that overrides the built-in logic for generating a caption.
isTotal
Default `FALSE` - specify `TRUE` to mark that this data group is a total.
isLevelSubTotal
Default `FALSE` - specify `TRUE` to mark that this data group is a sub-total within a level.
isLevelTotal
Default `FALSE` - specify `TRUE` to mark that this data group is level total.
calculationGroupName
For calculation groups, this character value specifies the calculation group that `calculationName` belongs to.
calculationName
For calculation groups, this character value specifies the name of the calculation.
baseStyleName
The style name for the data group.
styleDeclarations
A list of CSS style declarations to overlay on top of the base style.
insertAtIndex
An integer that specifies the index in the list of child groups where the new group should be inserted.
insertBeforeGroup
Specifies an existing group that the new group should be inserted before.
insertAfterGroup
Specifies an existing group that the new group should be inserted after
mergeEmptySpace
A 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.
cellBaseStyleName
The style name for cells related to this data group.
cellStyleDeclarations
A list of CSS style declarations to overlay on top of the base style for cells related to this data group
sortAnchor
Used to specify sort behaviour for outline groups, must be one of "fixed", "next" or "previous".
outlineLinkedGroupId
Used to link an outline group to the value data group which has the child data groups.
resetCells
Default `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.
index
An index that specifies the location of the group to remove in the list of child groups.
group
A `PivotDataGroup` object to be removed. Only one of `index` or `group` needs to be specified.
resetCells
Default `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
)
removeAncestorsIfNoRemainingChildren
Default `FALSE` - specify `TRUE` to recursively remove ancestor groups if they have no remaining child groups.
removedRelatedOutlineGroups
Default `FALSE` - specify `TRUE` to remove related outline groups.
resetCells
Default `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
)
variableName
The name of the related column in the data frame(s) of the pivot table.
atLevel
The 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.
fromData
Default `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.
dataName
The name of the data frame (as specified in `pt$addData()`) to read the data group values from.
dataSortOrder
Must be one of "asc", "desc", "custom" or "none".
customSortOrder
A vector values sorted into the desired order.
caption
The template of data group captions to generate, default "value".
dataFormat
A character, list or custom function to format the data value.
dataFmtFuncArgs
A list that specifies any additional arguments to pass to a custom format function.
onlyCombinationsThatExist
Default `TRUE` to generate only combinations of data groups that exist in the data frame.
explicitListOfValues
A 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.
calculationGroupName
The calculation group that the new data groups are related to.
expandExistingTotals
Default `FALSE`, which means totals are not broken down in multi-level hierarchies.
addTotal
Default `TRUE`, which means sub-total and total data groups are automatically added.
visualTotals
Default `FALSE`, which means visual totals are disabled. See the "Data Groups" vignette for more details about visual totals.
totalPosition
Either "before" or "after" to specify where total groups are created, default "after".
totalCaption
The caption to display on total groups, default "Total".
onlyAddGroupIf
A 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`.
preGroupData
Default `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
baseStyleName
The 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.
styleDeclarations
CSS style declarations that can override the base style, expressed as a list, e.g. `list("font-weight"=bold")`.
outlineBefore
Default `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.
outlineAfter
Default `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.
outlineTotal
Default `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.
onlyAddOutlineChildGroupIf
A 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
)
levelNumber
The 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.
orderBy
Must 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.
customOrder
A vector values sorted into the desired order.
sortOrder
Must be either "asc" or "desc".
calculationGroupName
If sorting using a calculation, the name of the calculation group containing the specified calculation.
calculationName
If sorting using a calculation, the name of the calculation.
fromIndex
A boundary to limit the sort operation.
toIndex
A boundary to limit the sort operation.
resetCells
Default `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
)
calculationGroupName
The name of the calculation group to add into the data group hierarchy.
atLevel
The 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.
outlineBefore
Default `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.
outlineAfter
Default `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.
resetCells
Default `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
)
matchMode
Either "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.
variableNames
A 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.
variableValues
A 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.
totals
A word that specifies how totals are matched (overrides the finer settings above) - must be one of "include" (default), "exclude" or "only".
calculationNames
A character vector specifying the name/names of the calculations to find.
atLevels
An integer vector constraining the levels in the hierarchy to search.
minChildCount
Match only data groups with this minimum number of children.
maxChildCount
Match only data groups with this maximum number of children.
emptyGroups
A word that specifies how empty groups are matched - must be one of "include", "exclude" (default) or "only".
outlineGroups
A 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
)
matchMode
Either "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.
variableNames
A 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.
variableValues
A 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.
totals
A word that specifies how totals are matched (overrides the finer settings above) - must be one of "include" (default), "exclude" or "only".
calculationNames
A character vector specifying the name/names of the calculations to find.
atLevels
An integer vector constraining the levels in the hierarchy to search.
minChildCount
Match only data groups with this minimum number of children.
maxChildCount
Match only data groups with this maximum number of children.
emptyGroups
A word that specifies how empty groups are matched - must be one of "include", "exclude" (default) or "only".
outlineGroups
A 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.
includeDescendantGroups
Default `FALSE`. Specify true to also return all descendants of data groups that match the specified criteria.
includeCurrentGroup
Default `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.