| PivotCells {pivottabler} | R Documentation |
R6 class that contains the cells in a pivot table.
Description
The 'PivotCells' class contains all of the 'PivotCell' instances that comprise the body of a pivot table.
Format
R6Class object.
Active bindings
rowCountThe number of rows in the pivot table (excluding column headings).
columnCountThe number of columns in the pivot table (excluding column headings).
rowGroupsA list of the leaf-level data groups on the rows axis.
columnGroupsA list of the leaf-level data groups on the columns axis.
rowsA list of the rows in the pivot table. Each element in this list is a list of 'PivotCell' objects comprising the row.
allA list of the cells in the pivot table. Each element in this list is a 'PivotCell' object.
Methods
Public methods
Method new()
Create a new 'PivotCells' object.
Usage
PivotCells$new(parentPivot = NULL)
Arguments
parentPivotThe pivot table that this 'PivotCells' instance belongs to.
Returns
A new 'PivotCells' object.
Method reset()
Remove all cells from the pivot table and reset row and column counts back to zero.
Usage
PivotCells$reset()
Returns
No return value.
Method getColumnGroup()
Get the leaf-level data group that is associated with a specific column or columns in the pivot table.
Usage
PivotCells$getColumnGroup(c = NULL)
Arguments
cThe column number or numbers. The first column is column 1, excluding the column(s) associated with row-headings.
Returns
A 'PivotDataGroup' that is associated with the specified column.
Method getRowGroup()
Get the leaf-level data group that is associated with a specific row or rows in the pivot table.
Usage
PivotCells$getRowGroup(r = NULL)
Arguments
rThe row number or numbers. The first row is row 1, excluding the row(s) associated with column-headings.
Returns
A 'PivotDataGroup' that is associated with the specified row
Method setGroups()
An internal method used when building the cell structure of the pivot table.
Usage
PivotCells$setGroups(rowGroups = NULL, columnGroups = NULL)
Arguments
rowGroupsA list of 'PivotDataGroup' objects to be set as the leaf-level row groups in the pivot table.
columnGroupsA list of 'PivotDataGroup' objects to be set as the leaf-level column groups in the pivot table.
Returns
No return value.
Method getCell()
Get the cell at the specified row and column coordinates in the pivot table.
Usage
PivotCells$getCell(r = NULL, c = NULL)
Arguments
rRow number of the cell to retrieve.
cColumn number of the cell to retrieve.
Details
The row and column numbers refer only to the cells in the body of the pivot table, i.e. row and column headings are excluded, e.g. row 1 is the first row of cells underneath the column headings.
Returns
A 'PivotCell' object representing the cell.
Method setCell()
Set the cell at the specified row and column coordinates in the pivot table.
Usage
PivotCells$setCell(r, c, cell)
Arguments
rRow number of the cell to retrieve.
cColumn number of the cell to retrieve.
cellA 'PivotCell' object to set into the pivot table cells.
Details
This method is intended for internal package use only, used when building # the cell structure. The row and column numbers refer only to the cells in the body of the pivot table, i.e. row and column headings are excluded, e.g. row 1 is the first row of cells underneath the column headings.
Returns
No return value.
Method getCells()
Retrieve cells by a combination of row and/or column numbers. See the "Finding and Formatting" vignette for graphical examples.
Usage
PivotCells$getCells( specifyCellsAsList = TRUE, rowNumbers = NULL, columnNumbers = NULL, cellCoordinates = NULL, excludeEmptyCells = FALSE, groups = NULL, rowGroups = NULL, columnGroups = NULL, matchMode = "simple" )
Arguments
specifyCellsAsListSpecify how cells are retrieved. Default 'TRUE'. More information is provided in the details section.
rowNumbersA vector of row numbers that specify the rows or cells to retrieve.
columnNumbersA vector of row numbers that specify the columns or cells to retrieve.
cellCoordinatesA list of two-element vectors that specify the coordinates of cells to retrieve. Ignored when 'specifyCellsAsList=FALSE'.
excludeEmptyCellsDefault 'FALSE'. Specify 'TRUE' to exclude empty cells.
groupsA 'PivotDataGroup' object or a list of 'PivotDataGroup' objects on either the rows or columns axes. The cells to be retrieved must be related to at least one of these groups.
rowGroupsA 'PivotDataGroup' object or a list of 'PivotDataGroup' objects on the rows axis. The cells to be retrieved must be related to at least one of these row groups. If both 'rowGroups' and 'columnGroups' are specified, then the cells to be retrieved must be related to at least one of the specified row groups and one of the specified column groups.
columnGroupsA 'PivotDataGroup' object or a list of 'PivotDataGroup' objects on the columns axis. The cells to be retrieved must be related to at least one of these column groups. If both 'rowGroups' and 'columnGroups' are specified, then the cells to be retrieved must be related to at least one of the specified row groups and one of the specified column groups.
matchModeEither "simple" (default) or "combinations"
"simple" specifies that row and column arguments are considered separately (logical OR), e.g. rowNumbers=1 and columnNumbers=2 will match all cells in row 1 and all cells in column 2.
"combinations" specifies that row and column arguments are considered together (logical AND), e.g. rowNumbers=1 and columnNumbers=2 will match only the cell single at location (1, 2).
Arguments 'rowNumbers', 'columnNumbers', 'rowGroups' and 'columnGroups' are affected by the match mode. All other arguments are not.
Details
When 'specifyCellsAsList=TRUE' (the default):
Get one or more rows by specifying the row numbers as a vector as
the rowNumbers argument and leaving the columnNumbers argument set
to the default value of 'NULL', or
Get one or more columns by specifying the column numbers as a vector
as the columnNumbers argument and leaving the rowNumbers argument
set to the default value of 'NULL', or
Get one or more individual cells by specifying the cellCoordinates
argument as a list of vectors of length 2, where each element in the
list is the row and column number of one cell,
e.g. 'list(c(1, 2), c(3, 4))' specifies two cells, the first located
at row 1, column 2 and the second located at row 3, column 4.
When 'specifyCellsAsList=FALSE':
Get one or more rows by specifying the row numbers as a vector as the
rowNumbers argument and leaving the columnNumbers argument set to the
default value of 'NULL', or
Get one or more columns by specifying the column numbers as a vector
as the columnNumbers argument and leaving the rowNumbers argument set
to the default value of 'NULL', or
Get one or more cells by specifying the row and column numbers as vectors
for the rowNumbers and columnNumbers arguments, or
a mixture of the above, where for entire rows/columns the element in the
other vector is set to 'NA', e.g. to retrieve whole rows, specify the row
numbers as the rowNumbers but set the corresponding elements in the
columnNumbers vector to 'NA'.
Returns
A list of 'PivotCell' objects.
Method findCells()
Find cells matching specified criteria. See the "Finding and Formatting" vignette for graphical examples.
Usage
PivotCells$findCells( variableNames = NULL, variableValues = NULL, totals = "include", calculationNames = NULL, minValue = NULL, maxValue = NULL, exactValues = NULL, valueRanges = NULL, includeNull = TRUE, includeNA = TRUE, emptyCells = "include", outlineCells = "exclude", rowNumbers = NULL, columnNumbers = NULL, cellCoordinates = NULL, groups = NULL, rowGroups = NULL, columnGroups = NULL, rowColumnMatchMode = "simple", cells = NULL, lowN = NULL, highN = NULL )
Arguments
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.
minValueA numerical value specifying a minimum value threshold.
maxValueA numerical value specifying a maximum value threshold.
exactValuesA vector or list specifying a set of allowed values.
valueRangesA vector specifying one or more value range expressions which the cell values must match. If multiple value range expressions are specified, then the cell value must match any of one the specified expressions.
includeNullSpecify TRUE to include 'NULL' in the matched cells, FALSE to exclude 'NULL' values.
includeNASpecify TRUE to include 'NA' in the matched cells, FALSE to exclude 'NA' values.
emptyCellsA word that specifies how empty cells are matched - must be one of "include" (default), "exclude" or "only".
outlineCellsA word that specifies how outline cells are matched - must be one of "include", "exclude" (default) or "only".
rowNumbersA vector of row numbers that specify the rows or cells to constrain the search.
columnNumbersA vector of column numbers that specify the columns or cells to constrain the search.
cellCoordinatesA list of two-element vectors that specify the coordinates of cells to constrain the search.
groupsA 'PivotDataGroup' object or a list of 'PivotDataGroup' objects on either the rows or columns axes. The cells to be searched must be related to at least one of these groups.
rowGroupsA 'PivotDataGroup' object or a list of 'PivotDataGroup' objects on the rows axis. The cells to be searched must be related to at least one of these row groups. If both 'rowGroups' and 'columnGroups' are specified, then the cells to be searched must be related to at least one of the specified row groups and one of the specified column groups.
columnGroupsA 'PivotDataGroup' object or a list of 'PivotDataGroup' objects on the columns axis. The cells to be searched must be related to at least one of these column groups. If both 'rowGroups' and 'columnGroups' are specified, then the cells to be searched must be related to at least one of the specified row groups and one of the specified column groups.
rowColumnMatchModeEither "simple" (default) or "combinations":
"simple" specifies that row and column arguments are considered separately (logical OR), e.g. rowNumbers=1 and columnNumbers=2 will match all cells in row 1 and all cells in column 2.
"combinations" specifies that row and column arguments are considered together (logical AND), e.g. rowNumbers=1 and columnNumbers=2 will match only the cell single at location (1, 2).
Arguments 'rowNumbers', 'columnNumbers', 'rowGroups' and 'columnGroups' are affected by the match mode. All other arguments are not.cellsA 'PivotCell' object or a list of 'PivotCell' objects to constrain the scope of the search.
lowNFind the first N cells (ascending order, lowest values first).
highNFind the last N cells (descending order, highest values first).
Returns
A list of 'PivotCell' objects.
Method findGroupColumnNumbers()
Find the column numbers associated with a specific data group or groups.
Usage
PivotCells$findGroupColumnNumbers(group = NULL, collapse = FALSE)
Arguments
groupA 'PivotDataGroup' in the column data groups (i.e. a column heading) or a list of column data groups..
collapseA logical value specifying whether the return value should be simplified. See details.
Details
If 'group' is a list: If 'collapse' is 'FALSE', then a list of vectors is returned, if 'collapse' is 'TRUE', then a single combined vector is returned.
Returns
Either a vector of column numbers related to the single specified group or a list of vectors containing column numbers related to the specified groups.
Method findGroupRowNumbers()
Find the row numbers associated with a specific data group or groups.
Usage
PivotCells$findGroupRowNumbers(group = NULL, collapse = FALSE)
Arguments
groupA 'PivotDataGroup' in the row data groups (i.e. a row heading) or a list of row data groups.
collapseA logical value specifying whether the return value should be simplified. See details.
Details
If 'group' is a list: If 'collapse' is 'FALSE', then a list of vectors is returned, if 'collapse' is 'TRUE', then a single combined vector is returned.
Returns
Either a vector of row numbers related to the single specified group or a list of vectors containing row numbers related to the specified groups.
Method getColumnWidths()
Retrieve the width (in characters) of the longest value in each column.
Usage
PivotCells$getColumnWidths()
Returns
A vector containing the length of the longest value in each column.
Method removeColumn()
Remove a column from the pivot table.
Usage
PivotCells$removeColumn(c = NULL, renumberGroups = TRUE)
Arguments
cThe column number. The first column is column 1, excluding the column(s) associated with row-headings.
renumberGroups'TRUE' (default) to renumber the 'rowColumnNumber' property of the data groups after removing the row.
Details
This method removes both the related column group and cells.
Returns
No return value.
Method removeColumns()
Remove multiple column from the pivot table.
Usage
PivotCells$removeColumns(columnNumbers = NULL, renumberGroups = TRUE)
Arguments
columnNumbersThe column numbers. The first column is column 1, excluding the column(s) associated with row-headings.
renumberGroups'TRUE' (default) to renumber the 'rowColumnNumber' property of the data groups after removing the row.
Details
This method removes both the related column groups and cells.
Returns
No return value.
Method removeRow()
Remove a row from the pivot table.
Usage
PivotCells$removeRow(r = NULL, renumberGroups = TRUE)
Arguments
rThe row number. The first row is row 1, excluding the row(s) associated with column-headings.
renumberGroups'TRUE' (default) to renumber the 'rowColumnNumber' property of the data groups after removing the row.
Details
This method removes both the related row group and cells.
Returns
No return value.
Method removeRows()
Remove multiple rows from the pivot table.
Usage
PivotCells$removeRows(rowNumbers = NULL, renumberGroups = TRUE)
Arguments
rowNumbersThe row numbers. The first row is row 1, excluding the rows(s) associated with column-headings.
renumberGroups'TRUE' (default) to renumber the 'rowColumnNumber' property of the data groups after removing the row.
Details
This method removes both the related row groups and cells.
Returns
No return value.
Method asMatrix()
Get a matrix containing all of the values from the body of the pivot table.
Usage
PivotCells$asMatrix(rawValue = TRUE)
Arguments
rawValue'TRUE' (default) to populate the matrix with the numerical raw values, 'FALSE' to populate the matrix with the character formatted values.
Returns
A 'matrix' containing the values from the body of the pivot table.
Method asList()
Return the contents of this object as a list for debugging.
Usage
PivotCells$asList()
Returns
A list of various object properties.
Method asJSON()
Return the contents of this object as JSON for debugging.
Usage
PivotCells$asJSON()
Returns
A JSON representation of various object properties.
Method clone()
The objects of this class are cloneable with this method.
Usage
PivotCells$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.