Title: | Create Pivot Tables |
---|---|
Description: | Create regular pivot tables with just a few lines of R. More complex pivot tables can also be created, e.g. pivot tables with irregular layouts, multiple calculations and/or derived calculations based on multiple data frames. Pivot tables are constructed using R only and can be written to a range of output formats (plain text, 'HTML', 'Latex' and 'Excel'), including with styling/formatting. |
Authors: | Christopher Bailiss [aut, cre] |
Maintainer: | Christopher Bailiss <[email protected]> |
License: | GPL-3 |
Version: | 1.5.5 |
Built: | 2025-02-01 04:13:31 UTC |
Source: | https://github.com/cbailiss/pivottabler |
A dataset containing details of the trains in the bhmtrains dataset that were partially/wholly cancelled and/or reinstated.
bhmtraindisruption
bhmtraindisruption
A data frame with 2982 rows and 10 variables:
Unique train identifier
Time of the last cancellation
3-letter code denoting the location of the last cancellation
The broad reason why the train was cancelled
A more specific reason why the train was cancelled
Time of the last reinstatement
Time of the last change of origin
3-letter code denoting the location of the last change of origin
The broad reason why the origin was changed
A more specific reason why the origin was changed
https://www.recenttraintimes.co.uk/
A dataset containing all of the trains that either originated at, passed through or terminated at Birmingham New Street railway station in the UK between 1st December 2016 and 28th February 2017 inclusive.
bhmtrains
bhmtrains
A data frame with 83710 rows and 16 variables:
Unique train identifier
Train status: A=Active, C=Cancelled, R=Reinstated
Train operating company
Express Passenger or Ordinary Passenger
DMU=Diesel Multiple Unit, EMU=Electrical Multiple Unit, HST=High Speed Train
Scheduled maximum speed (in miles per hour)
3-letter code denoting the scheduled origin of the train
Scheduled departure time in the Great Britain Train Timetable (GBTT) from the origin station
Actual departure time from the origin station
Scheduled arrival time in Birmingham in the GBTT
Actual arrival time in Birmingham in the GBTT
Scheduled departure time from Birmingham in the GBTT
Actual departure time from Birmingham in the GBTT
3-letter code denoting the scheduled destination of the train
Scheduled arrival time in the GBTT at the destination station
Actual arrival time at the destination station
https://www.recenttraintimes.co.uk/
checkArgument
is a utility function that provides basic assurances
about function argument values and generates standardised error messages when
invalid values are encountered.
checkArgument( argumentCheckMode, checkDataTypes, className, methodName, argumentValue, isMissing, allowMissing = FALSE, allowNull = FALSE, allowedClasses = NULL, mustBeAtomic = FALSE, allowedListElementClasses = NULL, listElementsMustBeAtomic = FALSE, allowedValues = NULL, minValue = NULL, maxValue = NULL, maxLength = NULL )
checkArgument( argumentCheckMode, checkDataTypes, className, methodName, argumentValue, isMissing, allowMissing = FALSE, allowNull = FALSE, allowedClasses = NULL, mustBeAtomic = FALSE, allowedListElementClasses = NULL, listElementsMustBeAtomic = FALSE, allowedValues = NULL, minValue = NULL, maxValue = NULL, maxLength = NULL )
argumentCheckMode |
A number between 0 and 4 specifying the checks to perform. |
checkDataTypes |
A logical value specifying whether the data types should be checked when argumentCheckMode=3 |
className |
The name of the calling class, for inclusion in error messages. |
methodName |
The name of the calling method, for inclusion in error messages. |
argumentValue |
The value to check. |
isMissing |
Whether the argument is missing in the calling function. |
allowMissing |
Whether missing values are permitted. |
allowNull |
Whether null values are permitted. |
allowedClasses |
The names of the allowed classes for argumentValue. |
mustBeAtomic |
Whether the argument value must be atomic. |
allowedListElementClasses |
For argument values that are lists(), the names of the allowed classes for the elements in the list. |
listElementsMustBeAtomic |
For argument values that are lists(), whether the list elements must be atomic. |
allowedValues |
For argument values that must be one value from a set list, the list of allowed values. |
minValue |
For numerical values, the lowest allowed value. |
maxValue |
For numerical values, the highest allowed value. |
maxLength |
For character values, the maximum allowed length (in characters) of the value. |
No return value. If invalid values are encountered, the
stop()
function is used to interrupt execution.
cleanCssValue
is a utility function that performs some basic cleanup
on CSS attribute values. Leading and trailing whitespace is removed. The
CSS values "initial" and "inherit" are blocked. The function is vectorised
so can be used with arrays.
cleanCssValue(cssValue)
cleanCssValue(cssValue)
cssValue |
The value to cleanup. |
The cleaned value.
cleanOutlineArg
checks values and provides defaults.
cleanOutlineArg( pvt, outline = NULL, defaultCaption = "{value}", defaultIsEmpty = TRUE )
cleanOutlineArg( pvt, outline = NULL, defaultCaption = "{value}", defaultIsEmpty = TRUE )
pvt |
The pivot table. |
outline |
Either a logical value (TRUE to use the default outline settings) or a list specifying outline settings. |
defaultCaption |
The default caption of the outline group. |
defaultIsEmpty |
Specify whether the outline group is empty or contains a value (typically a sub-total) |
A listed containing checked/cleaned outline group settings.
containsText
is a utility function returns TRUE if one text value is
present in another. Case sensitive. If textToSearch is a vector, returns
TRUE if any element contains textToFind.
containsText(textToSearch, textToFind)
containsText(textToSearch, textToFind)
textToSearch |
The value to be searched. |
textToFind |
The value to find. |
TRUE if the textToFind value is found.
convertPvtStyleToBasicStyle
is a utility function that converts a pivot
table style to a basictabler style from the basictabler package.
convertPvtStyleToBasicStyle(btbl = NULL, pvtStyle = NULL)
convertPvtStyleToBasicStyle(btbl = NULL, pvtStyle = NULL)
btbl |
The basic table that will own the new style. |
pvtStyle |
The pivot style to convert. |
a basictabler style.
convertPvtTblToBasicTbl
is a utility function that converts a pivot
table to a basic table from the basictabler package.
convertPvtTblToBasicTbl( pvt = NULL, exportOptions = NULL, compatibility = NULL, showRowGroupHeaders = FALSE )
convertPvtTblToBasicTbl( pvt = NULL, exportOptions = NULL, compatibility = NULL, showRowGroupHeaders = FALSE )
pvt |
The pivot table to convert. |
exportOptions |
Options specifying how values are exported. |
compatibility |
Compatibility options specified when creating the basictabler table. |
showRowGroupHeaders |
Show captions at the top of the columns that comprise the row groups (i.e. in the top left root of then pivot table). |
a basictabler table.
exportValueAs
is a utility function that returns either the
original value or a replacement placeholder value for export.
exportValueAs( rawValue, formattedValue, exportOptions, blankValue = character(0) )
exportValueAs( rawValue, formattedValue, exportOptions, blankValue = character(0) )
rawValue |
The raw value to check. |
formattedValue |
The formatted value to be exported. |
exportOptions |
A list of options controlling export behaviour. |
blankValue |
The 'placeholder' value to be exported when skipping the value. |
Either the original value or a placeholder value.
Get an empty theme for applying no styling to a table.
getBlankTheme(parentPivot, themeName = "blank")
getBlankTheme(parentPivot, themeName = "blank")
parentPivot |
Owning pivot table. |
themeName |
The name to use as the new theme name. |
A TableStyles object.
Get the compact theme for styling a pivot table.
getCompactTheme(parentPivot, themeName = "compact")
getCompactTheme(parentPivot, themeName = "compact")
parentPivot |
Owning pivot table. |
themeName |
The name to use as the new theme name. |
A PivotStyles object.
Get the default theme for styling a pivot table.
getDefaultTheme(parentPivot, themeName = "default")
getDefaultTheme(parentPivot, themeName = "default")
parentPivot |
Owning pivot table. |
themeName |
The name to use as the new theme name. |
A PivotStyles object.
Get the large plain theme for styling a pivot table.
getLargePlainTheme(parentPivot, themeName = "largeplain")
getLargePlainTheme(parentPivot, themeName = "largeplain")
parentPivot |
Owning pivot table. |
themeName |
The name to use as the new theme name. |
A PivotStyles object.
getNextPosition
is a utility function that helps when parsing strings
that contain delimiters.
getNextPosition(positions, afterPosition)
getNextPosition(positions, afterPosition)
positions |
An ordered numeric vector. |
afterPosition |
The value to start searching after. |
The first value in the array larger than afterPosition.
getPvtStyleDeclarations
is a utility function that reads the styles
from a pivot table style.
getPvtStyleDeclarations(pvtStyle = NULL)
getPvtStyleDeclarations(pvtStyle = NULL)
pvtStyle |
The pivot table style to read. |
a list of style declarations.
Get a simple coloured theme that can be used to style a pivot table into a custom colour scheme.
getSimpleColoredTheme( parentPivot, themeName = "coloredTheme", colors = NULL, fontName = NULL, theme = NULL )
getSimpleColoredTheme( parentPivot, themeName = "coloredTheme", colors = NULL, fontName = NULL, theme = NULL )
parentPivot |
Owning pivot table. |
themeName |
The name to use as the new theme name. |
colors |
The set of colours to use when generating the theme (see the Styling vignette for details). This parameter exists for backward compatibility. |
fontName |
The name of the font to use, or a comma separated list (for font-fall-back). This parameter exists for backward compatibility. |
theme |
A simple theme specified in the form of a list. See example for supported list elements (all other elements will be ignored). |
A 'PivotStyles' object.
pt <- PivotTable$new() # ... simpleBlueTheme <- list( fontName="Verdana, Arial", fontSize="0.75em", headerBackgroundColor = "rgb(68, 114, 196)", headerColor = "rgb(255, 255, 255)", cellBackgroundColor = "rgb(255, 255, 255)", cellColor = "rgb(0, 0, 0)", outlineCellBackgroundColor = "rgb(186, 202, 233)", outlineCellColor = "rgb(0, 0, 0)", totalBackgroundColor = "rgb(186, 202, 233)", totalColor = "rgb(0, 0, 0)", borderColor = "rgb(48, 84, 150)" ) pt$theme <- simpleBlueTheme # or theme <- getSimpleColoredTheme(pt, theme=simpleBlueTheme) # make further changes to the theme pt$theme <- theme
pt <- PivotTable$new() # ... simpleBlueTheme <- list( fontName="Verdana, Arial", fontSize="0.75em", headerBackgroundColor = "rgb(68, 114, 196)", headerColor = "rgb(255, 255, 255)", cellBackgroundColor = "rgb(255, 255, 255)", cellColor = "rgb(0, 0, 0)", outlineCellBackgroundColor = "rgb(186, 202, 233)", outlineCellColor = "rgb(0, 0, 0)", totalBackgroundColor = "rgb(186, 202, 233)", totalColor = "rgb(0, 0, 0)", borderColor = "rgb(48, 84, 150)" ) pt$theme <- simpleBlueTheme # or theme <- getSimpleColoredTheme(pt, theme=simpleBlueTheme) # make further changes to the theme pt$theme <- theme
Get the a theme for styling to a pivot table that looks more like a standard table (i.e. no row column headings).
getStandardTableTheme(parentPivot, themeName = "standardtable")
getStandardTableTheme(parentPivot, themeName = "standardtable")
parentPivot |
Owning pivot table. |
themeName |
The name to use as the new theme name. |
A PivotStyles object.
getTheme
returns the specified theme.
getTheme(parentPivot, themeName = NULL)
getTheme(parentPivot, themeName = NULL)
parentPivot |
Owning pivot table. |
themeName |
The name of the theme to retrieve. |
A PivotStyles object.
getXlBorderFromCssBorder
parses the CSS combined border declarations
(i.e. border, border-left, border-right, border-top, border-bottom) and
returns a list containing an openxlsx border style and color as separate
elements.
getXlBorderFromCssBorder(text)
getXlBorderFromCssBorder(text)
text |
The border declaration to parse. |
A list containing two elements: style and color.
getXlBorderStyleFromCssBorder
takes border parameters expressed as a
list (containing elements: width and style) and returns a border style that
is compatible with the openxlsx package.
getXlBorderStyleFromCssBorder(border)
getXlBorderStyleFromCssBorder(border)
border |
A list containing elements width and style. |
An openxlsx border style.
isNumericValue
is a utility function returns TRUE only when a numeric value
is present. NULL, NA, numeric(0) and integer(0) all return FALSE.
isNumericValue(value)
isNumericValue(value)
value |
The value to check. |
TRUE if a numeric value is present.
isTextValue
is a utility function returns TRUE only when a text value
is present. NULL, NA, character(0) and "" all return FALSE.
isTextValue(value)
isTextValue(value)
value |
The value to check. |
TRUE if a non-blank text value is present.
oneToNull
is a utility function that returns NULL when a value of
0 or 1 is passed to it, otherwise it returns the original value.
oneToNULL(value, convertOneToNULL)
oneToNULL(value, convertOneToNULL)
value |
The value to check. |
convertOneToNULL |
TRUE to convert 1 to NULL. |
NULL if value is 0 or 1, otherwise value.
parseColor
converts a colour value specified in CSS to a hex based
colour code. Example supported input values/formats/named colours are:
#0080FF, rgb(0, 128, 255), rgba(0, 128, 255, 0.5) and red, green, etc.
parseColor(color)
parseColor(color)
color |
The colour to convert. |
The colour as a hex code, e.g. #FF00A0.
parseCssBorder
parses the CSS combined border declarations (i.e.
border, border-left, border-right, border-top, border-bottom) and returns a
list containing the width, style and color as separate elements.
parseCssBorder(text)
parseCssBorder(text)
text |
The border declaration to parse. |
A list containing three elements: width, style and color.
parseCssSizeToPt
will take a CSS style and convert it to points.
Supported input size units are in, cm, mm, pt, pc, px, em,
are converted exactly: in, cm, mm, pt, pc: using 1in = 2.54cm = 25.4mm =
72pt = 6pc. The following are converted approximately: px, em,
approx 1em=16px=12pt and 100
parseCssSizeToPt(size)
parseCssSizeToPt(size)
size |
A size specified in common CSS units. |
The size converted to points.
parseCssSizeToPx
will take a CSS style and convert it to pixels
Supported input size units are in, cm, mm, pt, pc, px, em,
are converted exactly: in, cm, mm, pt, pc: using 1in = 2.54cm = 25.4mm =
72pt = 6pc. The following are converted approximately: px, em,
approx 1em=16px=12pt and 100
parseCssSizeToPx(size)
parseCssSizeToPx(size)
size |
A size specified in common CSS units. |
The size converted to pixels.
parseCssString
is a utility function that splits a string into a
vector/array. The function pays attention to text qualifiers (single and
double quotes) so won't split if the delimiter occurs inside a value.
parseCssString(text, separator = ",", removeEmptyString = TRUE)
parseCssString(text, separator = ",", removeEmptyString = TRUE)
text |
The text to split. |
separator |
The field separator, default comma. |
removeEmptyString |
TRUE to not return empty string / whitespace values. |
An R vector containing the values from text split up.
parseXlBorder
parses the combined xl border declarations (i.e.
xl-border, xl-border-left, xl-border-right, xl-border-top, xl-border-bottom)
and returns a list containing style and color as separate elements.
parseXlBorder(text)
parseXlBorder(text)
text |
The border declaration to parse. |
A list containing two elements: style and color.
The 'PivotBatch' class represents one combination of data, variables and calculations that are needed when calculating the values of cells in a pivot table.
R6Class
object.
The combination of data name and variable names defines a batch. When the batch is calculated, the calculations specified in the batch are evaluated against the specified data, with the data being grouped by the variables specified in the batch. Individual result values can then be retrieved from the batch. See the "Performance" vignette for details.
batchId
The unique identifier for the batch.
batchName
The unique name of the batch.
compatibleCount
The number of pivot cell calculations that this batch supports.
evaluated
TRUE if this batch has been evaluated.
results
The results (a data frame) of the evaluation of the batch
asString
A text description of the batch.
new()
Create a new 'PivotBatch' object.
PivotBatch$new( parentPivot = NULL, batchId = 0, dataName = NULL, variableNames = NULL, values = NULL, calculationName = NULL, calculationGroupName = NULL )
parentPivot
The pivot table that this 'PivotBatch' instance belongs to.
batchId
The unique identifier for the batch.
dataName
The name of the data frame (as specified in 'pt$addData()') that this batch relates to.
variableNames
Specifies the combination of variable names (i.e. dimensionality) of the batch.
values
A list specifying the distinct list of values for each variable, i.e. 'list(varName1=values1, varName2=values2, ...)'. 'values' is not currently used and does not affect the batch compatibility logic.
calculationName
The first calculation added to this batch. Does not affect the batch compatibility logic.
calculationGroupName
The calculation group of the first calculation added to this batch. Does not affect the batch compatibility logic.
A new 'PivotBatch' object.
isCompatible()
Determine whether a combination of data and variables is compatible with this batch.
PivotBatch$isCompatible(dataName = NULL, variableNames = NULL)
dataName
The name of the data frame (as specified in 'pt$addData()').
variableNames
Specifies the combination of variable names (i.e. dimensionality)..
'TRUE' or 'FALSE'.
addCompatible()
Add a new set of values or a new calculation to the batch. with this batch.
PivotBatch$addCompatible( values = NULL, calculationName = NULL, calculationGroupName = NULL )
values
A list specifying the distinct list of values for each variable, i.e. 'list(varName1=values1, varName2=values2, ...)'. 'values' is not currently used and does not affect the batch compatibility logic.
calculationName
The calculation to add to the batch. Does not affect the batch compatibility logic.
calculationGroupName
The calculation group of the calculation to add to the batch. Does not affect the batch compatibility logic.
No return value.
getCalculationInternalName()
Find the internal name of a calculation in the batch.
PivotBatch$getCalculationInternalName( calculationName = NULL, calculationGroupName = NULL )
calculationName
The name of the calculation to find.
calculationGroupName
The calculation group of the calculation to find.
The internal name of the calculation in the batch.
evaluateBatch()
Carry out grouping and calculations to evaluate the batch.
PivotBatch$evaluateBatch()
No return value.
getSummaryValueFromBatch()
Retrieve one calculation value from the batch, typically for the value of one cell in a pivot table.
PivotBatch$getSummaryValueFromBatch( filters = NULL, calculationName = NULL, calculationGroupName = NULL )
filters
A 'PivotFilters' instance that specifies which value to retrieve. This filters object is a combination of the row, column and calculation filters.
calculationName
The name of the calculation value to retrieve.
calculationGroupName
The calculation group of the calculation to retrieve.
A single calculation value.
clone()
The objects of this class are cloneable with this method.
PivotBatch$clone(deep = FALSE)
deep
Whether 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.
# This class should only be created by the pivot table. # It is not intended to be created outside of the pivot table.
The 'PivotBatchCalculator' class calculates the values for multiple cells in the pivot table in one evaluation step (per batch), instead of evaluating every calculation once per pivot table cell.
R6Class
object.
Evaluating a set of filters and calculations repetitively for each cell is inefficient and slow. The Batch Calculator executes a much small number of calculations which greatly reduces the CPU time and elapsed time required. See the "Performance" vignette for details.
batchCount
The number of batches generated for the pivot table.
calculationSummary
A summary of the batch compatibility for each calculation.
batchSummary
A summary of the batches in the pivot table.
PivotBatchCalculator$generateBatchesForNamedCalculationEvaluation1()
PivotBatchCalculator$generateBatchesForNamedCalculationEvaluation2()
new()
Create a new 'PivotBatchCalculator' object.
PivotBatchCalculator$new(parentPivot = NULL)
parentPivot
The pivot table that this 'PivotBatchCalculator' instance belongs to.
A new 'PivotBatchCalculator' object.
reset()
Reset the batch calculator, clearing all existing batches.
PivotBatchCalculator$reset()
No return value.
checkValidWorkingData()
Run some additional checks to see whether the working data is valid. Typically only used in development builds of the package.
PivotBatchCalculator$checkValidWorkingData(workingData = NULL)
workingData
The working data to check.
No return value.
isFiltersBatchCompatible()
Examines a set of filters to see whether they are compatible with batch evaluation mode. Only filters that specify zero or one value for each variable are compatible with batch evaluation.
PivotBatchCalculator$isFiltersBatchCompatible(filters = NULL)
filters
A 'PivotFilters' object that represents a set of filters to examine.
It is not practical to make batch evaluation work where a filter matches more than one value for a variable. One approach might be to add a derived column where a single value represents the multiple values, however the combination of values could partially overlap with combinations of values in other data groups. Also the value that represents the "combined" value could collide with other existing values in the column. In summary: Sequential mode is slower and more flexible. Batch is faster but stricter. Batch mode works for regular pivot tables (i.e. most cases).
'TRUE' if the filters are batch compatible, 'FALSE' otherwise.
generateBatchesForNamedCalculationEvaluation1()
Generates a new batch or finds a relevant existing batch for a named calculation and single working filters object.
PivotBatchCalculator$generateBatchesForNamedCalculationEvaluation1( dataName = NULL, calculationName = NULL, calculationGroupName = NULL, workingFilters = NULL )
dataName
The name of the data frame (as specified in 'pt$addData()').
calculationName
The name of the calculation.
calculationGroupName
The calculation group of the calculation.
workingFilters
A 'PivotFilters' object that represents the working filters to generate the batch for.
The name of either the batch that was created or the relevant existing batch.
generateBatchesForNamedCalculationEvaluation2()
Generates one or more batches for the named calculations and set of working working data associated with a cell.
PivotBatchCalculator$generateBatchesForNamedCalculationEvaluation2( calculationName = NULL, calculationGroupName = NULL, workingData = NULL )
calculationName
The name of the calculation.
calculationGroupName
The calculation group of the calculation.
workingData
A list containing filter and/or filter overrides.
A wrapper around 'generateBatchesForNamedCalculationEvaluation1()', which invokes this function as appropriate, depending on whether a calculation if either of type "summary" or type "calculation".
One or more batch names of either the batches that were created or the relevant existing batches.
generateBatchesForCellEvaluation()
Generates the batches for batch evaluation mode.
PivotBatchCalculator$generateBatchesForCellEvaluation()
One or more batch names of either the batches that were created or the relevant existing batches.
evaluateBatches()
Evaluate each of the batches defined in the batch calculator.
PivotBatchCalculator$evaluateBatches()
The number of batches that were evaluated.
getSummaryValueFromBatch()
Retrieve one calculation value from one batch, typically for the value of one cell in a pivot table.
PivotBatchCalculator$getSummaryValueFromBatch( batchName = NULL, calculationName = NULL, calculationGroupName = NULL, workingFilters = NULL )
batchName
The name of the batch containing the calculation result.
calculationName
The name of the calculation.
calculationGroupName
The calculation group of the calculation.
workingFilters
A 'PivotFilters' object that represents the working filters to retrieve the value for.
A single calculation value.
clone()
The objects of this class are cloneable with this method.
PivotBatchCalculator$clone(deep = FALSE)
deep
Whether 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.
# This class should only be created by the pivot table. # It is not intended to be created outside of the pivot table.
The 'PivotBatchStatistics' class contains a set of summary statistics that track how many calculations are batch compatible/incompatible.
R6Class
object.
asString
A text description of the batch statistics.
new()
Create a new 'PivotBatchStatistics' object.
PivotBatchStatistics$new(parentPivot = NULL)
parentPivot
The pivot table that this 'PivotBatchStatistics' instance belongs to.
A new 'PivotBatchStatistics' object.
reset()
Clear the batch statistics.
PivotBatchStatistics$reset()
No return value.
incrementNoData()
Increment the noData count for a batch.
PivotBatchStatistics$incrementNoData( calculationName = NULL, calculationGroupName = NULL )
calculationName
The name of the calculation to increment the count for.
calculationGroupName
The name of the calculation group for the calculation.
No return value.
incrementCompatible()
Increment the compatible count for a batch.
PivotBatchStatistics$incrementCompatible( calculationName = NULL, calculationGroupName = NULL )
calculationName
The name of the calculation to increment the count for.
calculationGroupName
The name of the calculation group for the calculation.
No return value.
incrementIncompatible()
Increment the incompatible count for a batch.
PivotBatchStatistics$incrementIncompatible( calculationName = NULL, calculationGroupName = NULL )
calculationName
The name of the calculation to increment the count for.
calculationGroupName
The name of the calculation group for the calculation.
No return value.
clone()
The objects of this class are cloneable with this method.
PivotBatchStatistics$clone(deep = FALSE)
deep
Whether 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.
# This class should only be created by the pivot table. # It is not intended to be created outside of the pivot table.
The 'PivotCalculation' class defines one calculation in a pivot table.
R6Class
object.
calculationName
Calculation unique name.
caption
Calculation 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.
displayOrder
The order the calculations are displayed in the pivot table.
filters
Any 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.
format
A character, list or custom function to format the calculation result.
fmtFuncArgs
A list that specifies any additional arguments to pass to a custom format function.
dataName
Specifies which data frame in the pivot table is used for this calculation (as specified in 'pt$addData()').
type
The calculation type: "summary", "calculation", "function" or "value".
valueName
For type="value", the name of the column containing the value to display in the pivot table.
summariseExpression
For type="summary", either the dplyr expression to use with dplyr::summarise() or a data.table calculation expression.
calculationExpression
For type="calculation", an expression to combine aggregate values.
calculationFunction
For type="function", a reference to a custom R function that will carry out the calculation.
calcFuncArgs
For type="function", a list that specifies additional arguments to pass to calculationFunction.
basedOn
A character vector specifying the names of one or more calculations that this calculation depends on.
noDataValue
An integer or numeric value specifying the value to use if no data exists for a particular cell.
noDataCaption
A character value that will be displayed by the pivot table if no data exists for a particular cell.
headingBaseStyleName
The name of a style defined in the pivot table to use as the base styling for the data group heading.
headingStyleDeclarations
A list of CSS style declarations (e.g. 'list("font-weight"="bold")') to override the base style.
cellBaseStyleName
The name of a style defined in the pivot table to use as the base styling for the cells related to this calculation.
cellStyleDeclarations
A list of CSS style declarations (e.g. 'list("font-weight"="bold")') to override the base style.
new()
Create a new 'PivotCalculation' object.
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 )
parentPivot
The pivot table that this 'PivotCalculation' instance belongs to.
calculationName
Calculation unique name.
caption
Calculation 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.
displayOrder
The order the calculations are displayed in the pivot table.
filters
Any 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.
format
A character, list or custom function to format the calculation result.
fmtFuncArgs
A list that specifies any additional arguments to pass to a custom format function.
dataName
Specifies which data frame in the pivot table is used for this calculation (as specified in 'pt$addData()').
type
The calculation type: "summary", "calculation", "function" or "value".
valueName
For type="value", the name of the column containing the value to display in the pivot table.
summariseExpression
For type="summary", either the dplyr expression to use with dplyr::summarise() or a data.table calculation expression.
calculationExpression
For type="calculation", an expression to combine aggregate values.
calculationFunction
For type="function", a reference to a custom R function that will carry out the calculation.
calcFuncArgs
For type="function", a list that specifies additional arguments to pass to calculationFunction.
basedOn
A character vector specifying the names of one or more calculations that this calculation depends on.
noDataValue
An integer or numeric value specifying the value to use if no data exists for a particular cell.
noDataCaption
A character value that will be displayed by the pivot table if no data exists for a particular cell.
headingBaseStyleName
The name of a style defined in the pivot table to use as the base styling for the data group heading.
headingStyleDeclarations
A list of CSS style declarations (e.g. 'list("font-weight"="bold")') to override the base style.
cellBaseStyleName
The name of a style defined in the pivot table to use as the base styling for the cells related to this calculation.
cellStyleDeclarations
A list of CSS style declarations (e.g. 'list("font-weight"="bold")') to override the base style.
A new 'PivotCalculation' object.
asList()
Return the contents of this object as a list for debugging.
PivotCalculation$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
PivotCalculation$asJSON()
A JSON representation of various object properties.
asString()
Return a representation of this object as a character value.
PivotCalculation$asString()
A character summary of various object properties.
clone()
The objects of this class are cloneable with this method.
PivotCalculation$clone(deep = FALSE)
deep
Whether 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.
# This class should only be created by the pivot table. # It is not intended to be created outside of the pivot table.
The 'PivotCalculationGroup' class is a container for multiple 'PivotCalculation' objects. Every pivot table has at least one pivot calculation group and this is sufficient for all regular pivot tables. Additional calculation groups are typically only created for irregular/custom pivot tables. See the "Irregular Layout" vignette for an example.
R6Class
object.
calculationGroupName
The name of the calculation group.
defaultCalculationName
The name of the default calculation in this calculation group.
count
The number of calculations in this calculation group.
calculations
A list containing the calculations in this group.
visibleCount
The number of visible calculations in this calculation group.
visibleCalculations
A list containing the visible calculations in this group.
new()
Create a new 'PivotCalculationGroup' object.
PivotCalculationGroup$new(parentPivot, calculationGroupName = NULL)
parentPivot
The pivot table that this 'PivotCalculationGroup' instance belongs to.
calculationGroupName
Calculation group unique name. Recommendation: Do not have spaces in this name.
A new 'PivotCalculationGroup' object.
isExistingCalculation()
Check whether a calculation already exists in this calculation group.
PivotCalculationGroup$isExistingCalculation(calculationName = NULL)
calculationName
group unique name.
'TRUE' if a calculation with the specified name exists in this calculation group object, 'FALSE' otherwise.
item()
Retrieve a calculation by index.
PivotCalculationGroup$item(index)
index
An integer specifying the calculation to retrieve.
The calculation that exists at the specified index.
getCalculation()
Retrieve a calculation by name.
PivotCalculationGroup$getCalculation(calculationName = NULL)
calculationName
The name of the calculation to retrieve.
The calculation with the specified name.
defineCalculation()
Create a new 'PivotCalculation' object.
PivotCalculationGroup$defineCalculation( 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 )
calculationName
Calculation unique name.
caption
Calculation 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.
displayOrder
The order the calculations are displayed in the pivot table.
filters
Any 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.
format
A character, list or custom function to format the calculation result.
fmtFuncArgs
A list that specifies any additional arguments to pass to a custom format function.
dataName
Specifies which data frame in the pivot table is used for this calculation (as specified in 'pt$addData()').
type
The calculation type: "summary", "calculation", "function" or "value".
valueName
For type="value", the name of the column containing the value to display in the pivot table.
summariseExpression
For type="summary", either the dplyr expression to use with dplyr::summarise() or a data.table calculation expression.
calculationExpression
For type="calculation", an expression to combine aggregate values.
calculationFunction
For type="function", a reference to a custom R function that will carry out the calculation.
calcFuncArgs
For type="function", a list that specifies additional arguments to pass to calculationFunction.
basedOn
A character vector specifying the names of one or more calculations that this calculation depends on.
noDataValue
An integer or numeric value specifying the value to use if no data exists for a particular cell.
noDataCaption
A character value that will be displayed by the pivot table if no data exists for a particular cell.
headingBaseStyleName
The name of a style defined in the pivot table to use as the base styling for the data group heading.
headingStyleDeclarations
A list of CSS style declarations (e.g. 'list("font-weight"="bold")') to override the base style.
cellBaseStyleName
The name of a style defined in the pivot table to use as the base styling for the cells related to this calculation.
cellStyleDeclarations
A list of CSS style declarations (e.g. 'list("font-weight"="bold")') to override the base style.
A new 'PivotCalculation' object.
asList()
Return the contents of this object as a list for debugging.
PivotCalculationGroup$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
PivotCalculationGroup$asJSON()
A JSON representation of various object properties.
asString()
Return a representation of this object as a character value.
PivotCalculationGroup$asString(seperator = ", ")
seperator
A character value used when concatenating the text representations of different calculations.
A character summary of various object properties.
clone()
The objects of this class are cloneable with this method.
PivotCalculationGroup$clone(deep = FALSE)
deep
Whether 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.
# This class should only be created by the pivot table. # It is not intended to be created outside of the pivot table.
The 'PivotCalculationGroups' class stores all of the calculation groups for a pivot table. Every pivot table has at least one pivot calculation group and this is sufficient for all regular pivot tables. Additional calculation groups are typically only created for irregular/custom pivot tables. See the "Irregular Layout" vignette for an example.
R6Class
object.
count
The number of calculation groups in the pivot table.
groups
A list containing the calculation groups in the pivot table.
defaultGroup
The default calculation group in the pivot table.
new()
Create a new 'PivotCalculationGroups' object.
PivotCalculationGroups$new(parentPivot)
parentPivot
The pivot table that this 'PivotCalculationGroups' instance belongs to.
A new 'PivotCalculationGroups' object.
isExistingCalculationGroup()
Check if a calculation group exists with the specified name.
PivotCalculationGroups$isExistingCalculationGroup(calculationGroupName = NULL)
calculationGroupName
The name of the calculation group.
'TRUE' if the calculation group already exists, 'FALSE' otherwise.
item()
Retrieve a calculation group by index.
PivotCalculationGroups$item(index)
index
An integer specifying the calculation group to retrieve.
The calculation group that exists at the specified index.
getCalculationGroup()
Retrieve a calculation group by name.
PivotCalculationGroups$getCalculationGroup(calculationGroupName = NULL)
calculationGroupName
The name of the calculation group to retrieve.
The calculation group with the specified name.
addCalculationGroup()
Create a new calculation group.
PivotCalculationGroups$addCalculationGroup(calculationGroupName = NULL)
calculationGroupName
The name of the calculation group to create
The new calculation group.
asList()
Return the contents of this object as a list for debugging.
PivotCalculationGroups$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
PivotCalculationGroups$asJSON()
A JSON representation of various object properties.
asString()
Return a representation of this object as a character value.
PivotCalculationGroups$asString(seperator = ", ")
seperator
A character value used when concatenating the text representations of different calculation groups.
A character summary of various object properties.
clone()
The objects of this class are cloneable with this method.
PivotCalculationGroups$clone(deep = FALSE)
deep
Whether 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.
# This class should only be created by the pivot table. # It is not intended to be created outside of the pivot table.
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.
batchInfo
A summary of the batches used in evaluating the pivot table.
new()
Create a new 'PivotCalculator' object.
PivotCalculator$new(parentPivot = NULL)
parentPivot
The 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)
dataName
The 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)
dataName
The 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)
dataName
The name of the data frame (as specified in 'pt$addData()') that the "totals" data frame is associated with.
variableNames
The 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)
calculationGroupName
The 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 )
calculationGroupName
The name of the calculation group to retrieve.
calculationName
The 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)
variableName
The data frame column name the filter is associated with.
values
The 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)
variableName
The data frame column name the filter is associated with.
values
The 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" )
filters1
A 'PivotFilters' object.
filters2
A 'PivotFilters' object.
action
A 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")
filters
A 'PivotFilters' object.
filter
A 'PivotFilters' object.
action
A 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" )
filters
A 'PivotFilters' object.
variableName
The name of the variable (i.e. column) in the data frame that the criteria relates to.
values
The values that the specified variable will be filtered to.
action
A 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)
dataFrame
The data frame to filter.
filters
A 'PivotFilters' object containing the filter criteria.
dataName
The 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)
dataFrame
The data frame.
variableName
The 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)
value
The value to format.
format
Either 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.
fmtFuncArgs
If '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 )
rowColFilters
A 'PivotFilters' object containing the combined filters from the row data groups and column data groups.
calcFilters
Either 'PivotFilters' object or a 'PivotFilterOverrides' object containing filers defined as part of the calculation.
cell
A '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 )
calculationName
The name of the calculation.
calculationGroupName
The name of the calculation group.
rowColFilters
A 'PivotFilters' object containing the combined filters from the row data groups and column data groups.
cell
A '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)
cell
The 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 )
dataFrame
The data frame to retrieve the value from.
workingFilters
The relevant working data for the calculation.
valueName
The name of the variable to retrieve from the data frame.
format
The formatting to apply to the value. See 'formatValue()' for details.
fmtFuncArgs
Additional arguments for a custom format function. See 'formatValue()' for details.
noDataValue
A replacement raw value to use if the value is NULL.
noDataCaption
A 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 )
dataName
The name of the data frame (as specified in 'pt$addData()') containing the data.
dataFrame
The data frame to retrieve the value from.
workingFilters
The relevant working data for the calculation.
batchName
The name of the batch that contains the results of the calculation (if batch evaluation is in use and possible for this cell and calculation).
calculationName
The name of the calculation.
calculationGroupName
The name of the calculation group.
summaryName
The name of the summary (typically also the calculation name).
summariseExpression
The dplyr or data.table expression to aggregate and summarise the data.
format
The formatting to apply to the value. See 'formatValue()' for details.
fmtFuncArgs
Additional arguments for a custom format function. See 'formatValue()' for details.
noDataValue
A replacement raw value to use if the value is NULL.
noDataCaption
A 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 )
values
The results of other calculations, passed in the form of a list where the element names are the names of those other calculations.
calculationExpression
A character expression to be evaluated, e.g. "values$TotalIncome/values$SaleCount".
format
The formatting to apply to the value. See 'formatValue()' for details.
fmtFuncArgs
Additional arguments for a custom format function. See 'formatValue()' for details.
noDataValue
A replacement raw value to use if the value is NULL.
noDataCaption
A 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 )
workingFilters
The relevant working data for the calculation.
calculationFunction
The custom R function to invoke.
calcFuncArgs
Specifies any additional arguments (in the form of a list) that will be passed to the custom calculation function.
format
The formatting to apply to the value. See 'formatValue()' for details.
fmtFuncArgs
Additional arguments for a custom format function. See 'formatValue()' for details.
baseValues
The results of other calculations, passed in the form of a list where the element names are the names of those other calculations.
cell
A '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 )
calculationName
The name of the calculation to execute.
calculationGroupName
The calculation group that the calculation belongs to.
workingData
The relevant working data for the calculation.
cell
A '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 )
calculationName
The name of the calculation to execute.
calculationGroupName
The calculation group that the calculation belongs to.
rowColFilters
The 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)
cell
A '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)
deep
Whether 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.
# This class should only be created by the pivot table. # It is not intended to be created outside of the pivot table.
The 'PivotCell' class represents a cell in the body of a pivot table (i.e. not a row/column heading, rather a cell typically containing a numerical value).
R6Class
object.
instanceId
An integer value that uniquely identifies this cell. 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.
rowNumber
The row number of the cell. 1 = the first (i.e. top) data row.
columnNumber
The column number of the cell. 1 = the first (i.e. leftmost) data column.
calculationName
The name of the calculation that is displayed in the cell.
calculationGroupName
The name of the calculation group that owns the calculation.
isEmpty
'TRUE' if this cell contains no data (e.g. if it is part of a header / outline row), 'FALSE' otherwise.
rowFilters
A 'PivotFilters' object containing the filters applied to this cell from the row data groups (i.e. row headings).
columnFilters
A 'PivotFilters' object containing the filters applied to this cell from the column data groups (i.e. column headings).
rowColFilters
A 'PivotFilters' object containing the combined filters applied to this cell from both the row and column data groups.
calculationFilters
The set of filters that apply to this cell to support calculation logic. Either a 'PivotFilters' object or a 'PivotFilterOverrides' object. See the "Appendix: Calculations" vignette for details.
workingData
A list of filter objects that results when the 'rowColFilters' and 'calculationFilters' are combined prior to calculating the cell value. This is a list since some cells involve multiple calculations - where 'calc$type' is "calculation" or "function", the calculation can be based on the values of other calculations.
evaluationFilters
The same as 'workingData' generally, except when custom calculation functions modify the filters whilst executing.
rowLeafGroup
The row data group linked to this row.
columnLeafGroup
The column data group linked to this column.
isTotal
'TRUE' is this cell is a total, 'FALSE' otherwise-
rawValue
The raw cell value - i.e. unformatted, typically a numeric value.
formattedValue
The formatted value - typically a character value.
baseStyleName
The name of the style that defines the visual appearance of the cell.
style
A 'PivotStyle' object that assists in managing the CSS style declarations that override the base style.
new()
Create a new 'PivotCell' object.
PivotCell$new( parentPivot, rowNumber = NULL, columnNumber = NULL, calculationName = NULL, calculationGroupName = NULL, isEmpty = FALSE, rowFilters = NULL, columnFilters = NULL, rowColFilters = NULL, rowLeafGroup = NULL, columnLeafGroup = NULL )
parentPivot
The pivot table that this 'PivotCell' instance belongs to.
rowNumber
The row number of the cell. 1 = the first (i.e. top) data row.
columnNumber
The column number of the cell. 1 = the first (i.e. leftmost) data column.
calculationName
The name of the calculation that is displayed in the cell.
calculationGroupName
The name of the calculation group that owns the calculation.
isEmpty
'TRUE' if this cell contains no data (e.g. if it is part of a header / outline row), 'FALSE' otherwise.
rowFilters
A 'PivotFilters' object containing the filters applied to this cell from the row data groups (i.e. row headings).
columnFilters
A 'PivotFilters' object containing the filters applied to this cell from the column data groups (i.e. column headings).
rowColFilters
A 'PivotFilters' object containing the combined filters applied to this cell from both the row and column data groups.
rowLeafGroup
The row data group linked to this row.
columnLeafGroup
The column data group linked to this column.
A new 'PivotCell' object.
setStyling()
An internal method used to set style declarations on the cell. Using 'pt$setStyling(cells=x)' is preferred for users.
PivotCell$setStyling(styleDeclarations = NULL)
styleDeclarations
A list containing CSS style declarations.
No return value.
getCopy()
Non-functional legacy method soon to be removed.
PivotCell$getCopy()
Returns an empty list.
asList()
Return the contents of this object as a list for debugging.
PivotCell$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
PivotCell$asJSON()
A JSON representation of various object properties.
clone()
The objects of this class are cloneable with this method.
PivotCell$clone(deep = FALSE)
deep
Whether 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.
# This class should only be created by the pivot table. # It is not intended to be created outside of the pivot table.
The 'PivotCells' class contains all of the 'PivotCell' instances that comprise the body of a pivot table.
R6Class
object.
rowCount
The number of rows in the pivot table (excluding column headings).
columnCount
The number of columns in the pivot table (excluding column headings).
rowGroups
A list of the leaf-level data groups on the rows axis.
columnGroups
A list of the leaf-level data groups on the columns axis.
rows
A list of the rows in the pivot table. Each element in this list is a list of 'PivotCell' objects comprising the row.
all
A list of the cells in the pivot table. Each element in this list is a 'PivotCell' object.
new()
Create a new 'PivotCells' object.
PivotCells$new(parentPivot = NULL)
parentPivot
The pivot table that this 'PivotCells' instance belongs to.
A new 'PivotCells' object.
reset()
Remove all cells from the pivot table and reset row and column counts back to zero.
PivotCells$reset()
No return value.
getColumnGroup()
Get the leaf-level data group that is associated with a specific column or columns in the pivot table.
PivotCells$getColumnGroup(c = NULL)
c
The column number or numbers. The first column is column 1, excluding the column(s) associated with row-headings.
A 'PivotDataGroup' that is associated with the specified column.
getRowGroup()
Get the leaf-level data group that is associated with a specific row or rows in the pivot table.
PivotCells$getRowGroup(r = NULL)
r
The row number or numbers. The first row is row 1, excluding the row(s) associated with column-headings.
A 'PivotDataGroup' that is associated with the specified row
setGroups()
An internal method used when building the cell structure of the pivot table.
PivotCells$setGroups(rowGroups = NULL, columnGroups = NULL)
rowGroups
A list of 'PivotDataGroup' objects to be set as the leaf-level row groups in the pivot table.
columnGroups
A list of 'PivotDataGroup' objects to be set as the leaf-level column groups in the pivot table.
No return value.
getCell()
Get the cell at the specified row and column coordinates in the pivot table.
PivotCells$getCell(r = NULL, c = NULL)
r
Row number of the cell to retrieve.
c
Column number of the cell to retrieve.
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.
A 'PivotCell' object representing the cell.
setCell()
Set the cell at the specified row and column coordinates in the pivot table.
PivotCells$setCell(r, c, cell)
r
Row number of the cell to retrieve.
c
Column number of the cell to retrieve.
cell
A 'PivotCell' object to set into the pivot table cells.
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.
No return value.
getCells()
Retrieve cells by a combination of row and/or column numbers. See the "Finding and Formatting" vignette for graphical examples.
PivotCells$getCells( specifyCellsAsList = TRUE, rowNumbers = NULL, columnNumbers = NULL, cellCoordinates = NULL, excludeEmptyCells = FALSE, groups = NULL, rowGroups = NULL, columnGroups = NULL, matchMode = "simple" )
specifyCellsAsList
Specify how cells are retrieved. Default 'TRUE'. More information is provided in the details section.
rowNumbers
A vector of row numbers that specify the rows or cells to retrieve.
columnNumbers
A vector of row numbers that specify the columns or cells to retrieve.
cellCoordinates
A list of two-element vectors that specify the coordinates of cells to retrieve. Ignored when 'specifyCellsAsList=FALSE'.
excludeEmptyCells
Default 'FALSE'. Specify 'TRUE' to exclude empty cells.
groups
A '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.
rowGroups
A '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.
columnGroups
A '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.
matchMode
Either "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.
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'.
A list of 'PivotCell' objects.
findCells()
Find cells matching specified criteria. See the "Finding and Formatting" vignette for graphical examples.
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 )
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.
minValue
A numerical value specifying a minimum value threshold.
maxValue
A numerical value specifying a maximum value threshold.
exactValues
A vector or list specifying a set of allowed values.
valueRanges
A 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.
includeNull
Specify TRUE to include 'NULL' in the matched cells, FALSE to exclude 'NULL' values.
includeNA
Specify TRUE to include 'NA' in the matched cells, FALSE to exclude 'NA' values.
emptyCells
A word that specifies how empty cells are matched - must be one of "include" (default), "exclude" or "only".
outlineCells
A word that specifies how outline cells are matched - must be one of "include", "exclude" (default) or "only".
rowNumbers
A vector of row numbers that specify the rows or cells to constrain the search.
columnNumbers
A vector of column numbers that specify the columns or cells to constrain the search.
cellCoordinates
A list of two-element vectors that specify the coordinates of cells to constrain the search.
groups
A '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.
rowGroups
A '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.
columnGroups
A '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.
rowColumnMatchMode
Either "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.
cells
A 'PivotCell' object or a list of 'PivotCell' objects to constrain the scope of the search.
lowN
Find the first N cells (ascending order, lowest values first).
highN
Find the last N cells (descending order, highest values first).
A list of 'PivotCell' objects.
findGroupColumnNumbers()
Find the column numbers associated with a specific data group or groups.
PivotCells$findGroupColumnNumbers(group = NULL, collapse = FALSE)
group
A 'PivotDataGroup' in the column data groups (i.e. a column heading) or a list of column data groups..
collapse
A logical value specifying whether the return value should be simplified. See 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.
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.
findGroupRowNumbers()
Find the row numbers associated with a specific data group or groups.
PivotCells$findGroupRowNumbers(group = NULL, collapse = FALSE)
group
A 'PivotDataGroup' in the row data groups (i.e. a row heading) or a list of row data groups.
collapse
A logical value specifying whether the return value should be simplified. See 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.
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.
getColumnWidths()
Retrieve the width (in characters) of the longest value in each column.
PivotCells$getColumnWidths()
A vector containing the length of the longest value in each column.
removeColumn()
Remove a column from the pivot table.
PivotCells$removeColumn(c = NULL, renumberGroups = TRUE)
c
The 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.
This method removes both the related column group and cells.
No return value.
removeColumns()
Remove multiple column from the pivot table.
PivotCells$removeColumns(columnNumbers = NULL, renumberGroups = TRUE)
columnNumbers
The 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.
This method removes both the related column groups and cells.
No return value.
removeRow()
Remove a row from the pivot table.
PivotCells$removeRow(r = NULL, renumberGroups = TRUE)
r
The 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.
This method removes both the related row group and cells.
No return value.
removeRows()
Remove multiple rows from the pivot table.
PivotCells$removeRows(rowNumbers = NULL, renumberGroups = TRUE)
rowNumbers
The 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.
This method removes both the related row groups and cells.
No return value.
asMatrix()
Get a matrix containing all of the values from the body of the pivot table.
PivotCells$asMatrix(rawValue = TRUE)
rawValue
'TRUE' (default) to populate the matrix with the numerical raw values, 'FALSE' to populate the matrix with the character formatted values.
A 'matrix' containing the values from the body of the pivot table.
asList()
Return the contents of this object as a list for debugging.
PivotCells$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
PivotCells$asJSON()
A JSON representation of various object properties.
clone()
The objects of this class are cloneable with this method.
PivotCells$clone(deep = FALSE)
deep
Whether 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.
# This class should only be created by the pivot table. # It is not intended to be created outside of the pivot table.
The PivotData class stores all of the data frames associated with a pivot table. Each data frame can have a set of associated "totals" data frames, which are used to enable the "value" calculation type.
R6Class
object.
count
The number of named data frames in the pivot table (excluding totals/aggregate data frames).
defaultData
The default data frame in the pivot table.
defaultName
The name of the default data frame in the pivot table.
new()
Create a new 'PivotData' object.
PivotData$new(parentPivot = NULL)
parentPivot
The pivot table that this 'PivotData' instance belongs to.
A new 'PivotData' object.
addData()
Add a data frame to the pivot table, specifying a name that can be used later to easily retrieve it or refer to it.
PivotData$addData(dataFrame = NULL, dataName = NULL)
dataFrame
The data frame to add to the pivot table.
dataName
The name to assign to this data frame in the pivot table. If no name is specified, then the name of the data frame variable will be used.
No return value.
getData()
Retrieve the data frame with the specified name.
PivotData$getData(dataName = NULL)
dataName
The name that was assigned to the data frame when it was added to the pivot table.
A data frame.
isKnownData()
Check if a data frame exists with the specified name.
PivotData$isKnownData(dataName = NULL)
dataName
The name that was assigned to the data frame when it was added to the pivot table.
'TRUE' if a data frame exists with the specified name, 'FALSE' otherwise.
addTotalData()
Add pre-calculated totals/aggregate data to the pivot table.
PivotData$addTotalData(dataFrame = NULL, dataName = NULL, variableNames = NULL)
dataFrame
The data frame to add to the pivot table.
dataName
The name of the associated data frame in the pivot table which these totals relate to.
variableNames
A character vector specifying the names of the variables which these totals are grouped by.
No return value.
countTotalData()
Count the number of data frames containing total/aggregate data that exist in the pivot table associated with a specific named data frame.
PivotData$countTotalData(dataName = NULL)
dataName
The name of the associated data frame in the pivot table which these totals relate to.
The number of total/aggregate data frames that exist in the pivot table associated with the specified data frame name.
getTotalData()
Retrieve pre-calculated totals/aggregate data from the pivot table.
PivotData$getTotalData(dataName = NULL, variableNames = NULL)
dataName
The name of the associated data frame in the pivot table which these totals relate to.
variableNames
A character vector specifying the names of the variables which the totals are grouped by.
A data frame.
asList()
Return the contents of this object as a list for debugging.
PivotData$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
PivotData$asJSON()
A JSON representation of various object properties.
clone()
The objects of this class are cloneable with this method.
PivotData$clone(deep = FALSE)
deep
Whether 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.
# This class should only be created by the pivot table. # It is not intended to be created outside of the pivot table.
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.
A new 'PivotDataGroup' object.
getLevelNumber()
Retrieve the level number in the hierarchy that the current data group exists at.
PivotDataGroup$getLevelNumber()
An integer value specifying the level number where the data group exists.
getAncestorGroups()
Get all of the data groups above the current data group in the parent-child data group hierarchy.
PivotDataGroup$getAncestorGroups(ancestors = NULL, includeCurrentGroup = FALSE)
ancestors
A list containing ancestors closer to the current data group - to enable recursive execution of this function, or 'NULL' to begin with.
includeCurrentGroup
Specify 'TRUE' to include the current group in the return value.
A list of data groups, where element 1 is the parent of the current group, element 2 is the grandparent of the current group, etc.
getDescendantGroups()
Get all of the data groups below the current data group in the parent-child data group hierarchy.
PivotDataGroup$getDescendantGroups( descendants = NULL, includeCurrentGroup = FALSE )
descendants
A list containing descendants closer to the current data group - to enable recursive execution of this function, or 'NULL' to begin with.
includeCurrentGroup
Specify 'TRUE' to include the current group in the return value.
A list of descendant data groups.
getLeafGroups()
Get all of the data groups below the current data group in the parent-child data group hierarchy.
PivotDataGroup$getLeafGroups(leafGroups = NULL)
leafGroups
A list containing other leaf-level groups - to enable recursive execution of this function, or 'NULL' to begin with.
A list of leaf-level data groups.
getLevelCount()
Count the number of levels in the data group hierarchy.
PivotDataGroup$getLevelCount(includeCurrentLevel = FALSE)
includeCurrentLevel
Default 'FALSE' to exclude the current level from the level count (since this method is most often called on the hidden root group).
The maximum number of levels in the hierarchy.
getLevelGroups()
Retrieve all of the data groups at a specific level in the data group hierarchy.
PivotDataGroup$getLevelGroups(level = NULL, levelGroups = NULL)
level
An integer specifying the level number. Level 0 represents the current data group.
levelGroups
A list containing groups accumulated so far - to enable recursive execution of this function, or 'NULL' to begin with.
A list of data groups at the specified level in the hierarchy.
getRelatedOutlineGroups()
Retrieve the a list of the typically two or three related data groups that were created as one outlined group.
PivotDataGroup$getRelatedOutlineGroups(group = NULL)
group
The group to find the related outline groups.
A list of related outline data groups.
getChildIndex()
Get the index of a child group (or groups) in the current groups list of child groups.
PivotDataGroup$getChildIndex(childGroup = NULL)
childGroup
A single data group or a list of data groups that are children of the current group.
An integer vector.
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.
PivotDataGroup$findChildIndex(childGroupInstanceId = NULL)
childGroupInstanceId
An integer vector containing the instance ids of child groups of the current group.
An integer vector.
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.
The new 'PivotDataGroup' object.
removeChildGroup()
Remove a data group that is a child of the current data group.
PivotDataGroup$removeChildGroup(index = NULL, group = NULL, resetCells = TRUE)
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.
No return value.
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.
No return value.
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.
A list of new 'PivotDataGroup' objects that have been added.
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.
No return value.
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.
A list of new 'PivotDataGroup' objects that have been added.
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.
PivotDataGroup$normaliseDataGroup(resetCells = TRUE)
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.
A list of new 'PivotDataGroup' objects that have been added.
getNetFilters()
Get a 'PivotFilters' object that contains the filters applied in this data group and all of its ancestors in the data group hierarchy.
PivotDataGroup$getNetFilters()
A 'PivotFilters' object.
getNetCalculationName()
Get the calculation name set in this data group or its nearest ancestor.
PivotDataGroup$getNetCalculationName()
The name of a calculation.
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.
'TRUE' if this group matches the specified criteria, 'FALSE' otherwise.
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.
A list of data groups matching the specified criteria.
setStyling()
An internal method used to set style declarations on the data group. Using 'pt$setStyling(cells=x)' is preferred for users.
PivotDataGroup$setStyling(styleDeclarations = NULL)
styleDeclarations
A list containing CSS style declarations.
No return value.
clearSortGroups()
An internal method that clears state data used during sorting operations.
PivotDataGroup$clearSortGroups()
No return value.
addSortGroupBefore()
An internal method used during sorting operations.
PivotDataGroup$addSortGroupBefore(grp)
grp
The group to insert as part of sorting.
No return value.
addSortGroupAfter()
An internal method used during sorting operations.
PivotDataGroup$addSortGroupAfter(grp)
grp
The group to insert as part of sorting.
No return value.
asList()
Return the contents of this object as a list for debugging.
PivotDataGroup$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
PivotDataGroup$asJSON()
A JSON representation of various object properties.
clone()
The objects of this class are cloneable with this method.
PivotDataGroup$clone(deep = FALSE)
deep
Whether 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.
# This class should only be created by the pivot table. # It is not intended to be created outside of the pivot table.
The 'PivotFilter' class represents a single filter condition.
R6Class
object.
The filter condition represented by a 'PivotFilter' instance relates to one data frame variable/column and is of the form [ColumnName] IN c(Value1, Value2, Value3, ...). Often in a pivot table, each filter specifies only one data value, as typically each distinct data value exists in a separate row or column. The 'PivotFilter' class contains methods to perform set based operations on filter values when combining filters.
variableName
The name of the column in the data frame that this filter applies to.
safeVariableName
The name of the column in the data frame that this filter applies to, surrounded by back-ticks if the name is not legal.
type
Either "ALL", "VALUES" or "NONE". "VALUES" is the most common type and means the data is filtered to a subset of values. "ALL" means there is no filtering, i.e. all values match. "NONE" means there can be no matching values/data.
values
The subset of values that this filter matches.
new()
Create a new 'PivotFilter' object.
PivotFilter$new(parentPivot, variableName = NULL, type = "ALL", values = NULL)
parentPivot
The pivot table that this 'PivotFilter' instance belongs to.
variableName
The name of the column in the data frame that this filter applies to.
type
Must be either "ALL", "VALUES" or "NONE". "VALUES" is the most common type and means the data is filtered to a subset of values. "ALL" means there is no filtering, i.e. all values match. "NONE" means there can be no matching values/data.
values
A single data value or a vector of multiple data values that this filter will match on.
A new 'PivotFilter' object.
intersect()
Updates this filter by intersecting the values in this filter with the values from another 'PivotFilter' object.
PivotFilter$intersect(filter)
filter
A 'PivotFilter' object.
No return value.
union()
Updates this filter by unioning the values in this filter with the values from another 'PivotFilter' object.
PivotFilter$union(filter)
filter
A 'PivotFilter' object.
No return value.
replace()
Updates this filter by replacing the values in this filter with the values from another 'PivotFilter' object.
PivotFilter$replace(filter)
filter
A 'PivotFilter' object.
No return value.
getCopy()
Create a copy of this 'PivotFilter' object.
PivotFilter$getCopy()
A copy of this 'PivotFilter' object.
asList()
Return the contents of this object as a list for debugging.
PivotFilter$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
PivotFilter$asJSON()
A JSON representation of various object properties.
asString()
Return a representation of this object as a character value.
PivotFilter$asString(includeVariableName = TRUE, seperator = " ")
includeVariableName
'TRUE' (default) to include the variable name in the string.
seperator
A character value used when concatenating multiple filter values.
A character summary of various object properties.
clone()
The objects of this class are cloneable with this method.
PivotFilter$clone(deep = FALSE)
deep
Whether to make a deep clone.
pt <- PivotTable$new() # ... PivotFilter$new(pt, variableName="Country", values="England")
pt <- PivotTable$new() # ... PivotFilter$new(pt, variableName="Country", values="England")
The 'PivotFilterOverrides' class contains multiple PivotFilter
objects that can be used later to override a set of filters, e.g. in a
pivot table calculation.
R6Class
object.
Each cell in a pivot table has context (i.e. filters) coming from the row and column groups that are applicable to the cell. The 'PivotFilterOverrides' class contains several different ways of changing this filter criteria as part of a calculation. In most use cases, only one of the available approaches will be used.
removeAllFilters
TRUE to remove all existing filters before applying any other and/replace/or filters.
keepOnlyFiltersFor
Specify the names of existing variables to retain the filters for. All other filters will be removed.
removeFiltersFor
Specify the names of variables to remove filters for.
overrideFunction
A custom R function to amend the filters in each cell.
countAnd
The number of 'PivotFilters' that will be combined with other pivot filters by intersecting their lists of allowed values.
countReplace
The number of 'PivotFilters' that will be combined with other pivot filters by entirely replacing existing PivotFilter objects.
countOr
The number of 'PivotFilters' that will be combined with other pivot filters by unioning their lists of allowed values.
countTotal
The total number of 'PivotFilters' that will be combined with other pivot filters.
andFilters
The 'PivotFilters' that will be combined with other pivot filters by intersecting their lists of allowed values.
replaceFilters
The 'PivotFilters' that will be combined with other pivot filters by entirely replacing existing PivotFilter objects.
orFilters
The 'PivotFilters' that will be combined with other pivot filters by unioning their lists of allowed values.
allFilters
The complete set of 'PivotFilters' that will be combined with other pivot filters.
new()
Create a new 'PivotFilterOverrides' object.
PivotFilterOverrides$new( parentPivot = NULL, removeAllFilters = FALSE, keepOnlyFiltersFor = NULL, removeFiltersFor = NULL, overrideFunction = NULL, filter = NULL, variableName = NULL, type = "ALL", values = NULL, action = "replace" )
parentPivot
The pivot table that this 'PivotFilterOverrides' instance belongs to.
removeAllFilters
Specifies whether to clear all existing filters, before applying the filter overrides. Default value 'FALSE'
keepOnlyFiltersFor
A character vector specifying the variable names to retain the filter criteria for. Filter criteria for all other variables will be cleared.
removeFiltersFor
A character vector specifying the variable names for which the filter criteria will be cleared. Filter criteria for all other variables will be retained.
overrideFunction
A custom R function which will be invoked for each cell to modify the filters before the calculation is carried out.
filter
A PivotFilter object containing filter criteria which will be combined with the current set of filters using the specified combine method.
variableName
The variable name for a new filter to apply to. Specified in conjunction with the 'type' and 'values' parameters.
type
The type of a new filter to apply, must be either "ALL", "VALUES" or "NONE".
values
A single data value or a vector of multiple data values that a new filter will match on.
action
Specifies how the new filter defined in 'filter' (or 'variableName', 'type' and 'values') should be combined with the existing filter criteria for the cell. Must be one of "intersect", "replace" or "union".
A new 'PivotFilterOverrides' object.
add()
Add additional filter criteria into this 'PivotFilterOverrides' object. Either 'filter' is specified, or 'variableName', 'type' and 'values' are specified.
PivotFilterOverrides$add( filter = NULL, variableName = NULL, type = "ALL", values = NULL, action = "replace" )
filter
A 'PivotFilter' to take criteria from.
variableName
The variable name the additional criteria applies to.
type
The type of the additional filter criteria, must be either "ALL", "VALUES" or "NONE".
values
A single data value or a vector of multiple data values that compromise the additional filter criteria.
action
Specifies how the additional filter should be combined with the existing filter criteria for the cell. Must be one of "intersect", "replace" or "union".
No return value.
apply()
Apply the filter overrides to an existing 'PivotFilters' object.
PivotFilterOverrides$apply(filters = NULL, cell = NULL)
filters
A 'PivotFilters' object to apply the filter overrides to.
cell
A 'PivotCell' object representing the cell that the 'filters' relate to.
No return value.
asList()
Return the contents of this object as a list for debugging.
PivotFilterOverrides$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
PivotFilterOverrides$asJSON()
A JSON representation of various object properties.
asString()
Return a representation of this object as a character value.
PivotFilterOverrides$asString(includeVariableName = TRUE, seperator = ", ")
includeVariableName
'TRUE' (default) to include the variable name in the string.
seperator
A character value used when concatenating multiple filter overrides.
A character summary of various object properties.
clone()
The objects of this class are cloneable with this method.
PivotFilterOverrides$clone(deep = FALSE)
deep
Whether to make a deep clone.
pt <- PivotTable$new() # ... # PivotFilterOverrides constructor allows a filter to be defined # e.g. to enable %of row or column type calculations filterOverrides <- PivotFilterOverrides$new(pt, keepOnlyFiltersFor="Volume") # Alternatively/in addition, create a new filter filter <- PivotFilter$new(pt, variableName="Country", values="England") # Add the filter to the set of overrides filterOverrides$add(filter=filter, action="replace")
pt <- PivotTable$new() # ... # PivotFilterOverrides constructor allows a filter to be defined # e.g. to enable %of row or column type calculations filterOverrides <- PivotFilterOverrides$new(pt, keepOnlyFiltersFor="Volume") # Alternatively/in addition, create a new filter filter <- PivotFilter$new(pt, variableName="Country", values="England") # Add the filter to the set of overrides filterOverrides$add(filter=filter, action="replace")
The 'PivotFilters' class allows multiple filter conditions relating to
different data frame columns to be combined, i.e. a 'PivotFilters' object
typically contains multiple PivotFilter
objects.
R6Class
object.
As well as acting as a container for multiple filter conditions, the
'PivotFilters' class also contains logic for combining filter.
The 'action' parameter in many of the methods controls how two filters
are combined.
Most common cases:
(1) When working out the rowColFilters for each pivot table cell, the
filters from the row and column leaf groups are combined using
'action="intersect"'.
(2) When combining the rowColFilters with calculation filters the
action could be any of (in order of most typical)
"intersect", "replace" or "union".
"intersect" would apply additional restrictions, e.g. see the
example in the Calculations vignette that has a measure for
weekend trains only.
"replace" would apply when doing things like percentage of row
total calculations - again, see example in the calculations vignette
"union" is probably much less likely (hard to envisage many
situations when that would be needed).
(3) In custom calculation functions, the action could be any of
"intersect", "replace" or "union".
NOTE: 'pivottabler' does not allow complex conditions to be built up,
such as ((A=X) or (B=Y)) and (C=2) since there is complex precedence
involved and conditions like this are not typical of pivot tables.
If they were really needed, a workaround would be to use a custom
calculation function and include this logic in that function.
See Appendix 2 vignette for many more complex calculation details.
count
The number of 'PivotFilter' objects in this 'PivotFilters' object.
filters
A list of 'PivotFilter' objects in this 'PivotFilters' object.
isALL
If TRUE, this 'PivotFilters' object matches all data.
isNONE
If TRUE, this 'PivotFilters' object matches no data.
filteredVariables
The names of the variables that are filtered by this 'PivotFilters' object.
filteredValues
A list of the criteria values for each of the variables filtered by this 'PivotFilters' object, where the list element names are the variable names.
new()
Create a new 'PivotFilters' object, optionally adding a filter.
PivotFilters$new( parentPivot = NULL, variableName = NULL, type = "ALL", values = NULL )
parentPivot
The pivot table that this 'PivotFilters' instance belongs to.
variableName
The name of the column in the data frame that this filter applies to. Specify 'NULL' to skip adding a filter.
type
Must be either "ALL", "VALUES" or "NONE". "VALUES" is the most common type and means the data is filtered to a subset of values. "ALL" means there is no filtering, i.e. all values match. "NONE" means there can be no matching values/data.
values
A single data value or a vector of multiple data values that the filter will match on.
A new 'PivotFilters' object.
clearFilters()
Remove all filters from this 'PivotFilters' object.
PivotFilters$clearFilters()
No return value.
keepOnlyFiltersFor()
Remove the filters for all variables except those specified.
PivotFilters$keepOnlyFiltersFor(variableNames = NULL)
variableNames
A character vector specifying the variable names to retain the filter criteria for. Filter criteria for all other variables will be cleared.
No return value.
removeFiltersFor()
Remove the filters for the specified variables.
PivotFilters$removeFiltersFor(variableNames = NULL)
variableNames
A character vector specifying the variable names for which the filter criteria will be cleared. Filter criteria for all other variables will be retained.
No return value.
getFilter()
Find a filter with the specified variable name.
PivotFilters$getFilter(variableName = NULL)
variableName
The variable name to find a filter for.
A 'PivotFilter' object that filters on the specified variable.
isFilterMatch()
Tests whether this 'PivotFilters' object matches specified criteria.
PivotFilters$isFilterMatch( matchMode = "simple", variableNames = NULL, variableValues = NULL )
matchMode
Either "simple" (default) or "combinations".
"simple" is used when matching only one variable-value, multiple
variable-value combinations are effectively logical "OR", i.e.
any one single 'PivotFilter' match means the 'PivotFilters' object
is a match.
"combinations" is used when matching for combinations of variable
values, multiple variable-value combinations are effectively
logical "AND", i.e. there must be a matching 'PivotFilter' for
every variable name / variable values criteria specified.
See the "Finding and Formatting" vignette for graphical examples.
variableNames
The variable name(s) to find a filter for. This can be a vector containing more than one variable name.
variableValues
A list specifying the variable names and values to find, e.g. 'variableValues=list("PowerType"=c("DMU", "HST"))'.
'TRUE' if this filters object matches the specified criteria, 'FALSE' otherwise.
setFilters()
Update the value of this 'PivotFilters' object with the filters from the specified 'PivotFilters' object, either intersecting, replacing or unioning the filter criteria.
PivotFilters$setFilters(filters = NULL, action = "replace")
filters
A 'PivotFilters' object.
action
Specifies how the criteria defined in 'filters' should be combined with the existing filter criteria. Must be one of "intersect", "replace" or "union".
No return value.
setFilter()
Update the value of this 'PivotFilters' object with the filters from the specified 'PivotFilter' object, either intersecting, replacing or unioning the filter criteria.
PivotFilters$setFilter(filter = NULL, action = "replace")
filter
A 'PivotFilter' object.
action
Specifies how the criteria defined in 'filter' should be combined with the existing filter criteria. Must be one of "intersect", "replace" or "union".
No return value.
setFilterValues()
Update the value of this 'PivotFilters' object with additional filter criteria, either intersecting, replacing or unioning the filter criteria.
PivotFilters$setFilterValues( variableName = NULL, type = "ALL", values = NULL, action = "replace" )
variableName
The name of the column in the data frame that this criteria applies to.
type
Must be either "ALL", "VALUES" or "NONE".
values
A single data value or a vector of multiple data values that comprise the additional filter criteria.
action
Specifies how the criteria defined in 'filter' should be combined with the existing filter criteria. Must be one of "intersect", "replace" or "union".
No return value.
addFilter()
Add a new 'PivotFilter' object to the filter list in this 'PivotFilters' object.
PivotFilters$addFilter(filter = NULL)
filter
A 'PivotFilter' object.
No return value.
getFilteredDataFrame()
Filters the specified data frame using the filters defined in this 'PivotFilters' object and returns the results as another data frame.
PivotFilters$getFilteredDataFrame(dataFrame = NULL)
dataFrame
A data frame to filter.
A data frame filtered according to the criteria in this 'PivotFilters' object.
getCopy()
Create a copy of this 'PivotFilters' object.
PivotFilters$getCopy()
A copy of this 'PivotFilters' object.
asList()
Return the contents of this object as a list for debugging.
PivotFilters$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
PivotFilters$asJSON()
A JSON representation of various object properties.
asString()
Return a representation of this object as a character value.
PivotFilters$asString(includeVariableName = TRUE, seperator = ", ")
includeVariableName
'TRUE' (default) to include the variable name in the string.
seperator
A character value used when concatenating multiple filters.
A character summary of various object properties.
clone()
The objects of this class are cloneable with this method.
PivotFilters$clone(deep = FALSE)
deep
Whether to make a deep clone.
pt <- PivotTable$new() # ... # PivotFilters constructor allows a filter to be defined filters <- PivotFilters$new(pt, variableName="Year", values=2017) # Create a new filter filter <- PivotFilter$new(pt, variableName="Country", values="England") # Combine the filters filters$setFilter(filter) # filters now contains criteria for both Year and Country # Now add another filter, this time via an alternative method filters$setFilterValues(variableName="Product", values="Cadbury Dairy Milk Chocolate 100g") # filters now contains criteria for Year, Country and Product
pt <- PivotTable$new() # ... # PivotFilters constructor allows a filter to be defined filters <- PivotFilters$new(pt, variableName="Year", values=2017) # Create a new filter filter <- PivotFilter$new(pt, variableName="Country", values="England") # Combine the filters filters$setFilter(filter) # filters now contains criteria for both Year and Country # Now add another filter, this time via an alternative method filters$setFilterValues(variableName="Product", values="Cadbury Dairy Milk Chocolate 100g") # filters now contains criteria for Year, Country and Product
The 'PivotHtmlRenderer' class creates a HTML representation of a pivot table.
R6Class
object.
new()
Create a new 'PivotHtmlRenderer' object.
PivotHtmlRenderer$new(parentPivot)
parentPivot
The pivot table that this 'PivotHtmlRenderer' instance belongs to.
A new 'PivotHtmlRenderer' object.
clearIsRenderedFlags()
An internal method used when rendering a pivot table to HTML. Clear the IsRendered flags that exist on the 'PivotDataGroup' class.
PivotHtmlRenderer$clearIsRenderedFlags()
No return value.
getTableHtml()
Generate a HTML representation of the pivot table, optionally including additional detail for debugging purposes.
PivotHtmlRenderer$getTableHtml( styleNamePrefix = NULL, includeHeaderValues = FALSE, includeRCFilters = FALSE, includeCalculationFilters = FALSE, includeWorkingData = FALSE, includeEvaluationFilters = FALSE, includeCalculationNames = FALSE, includeRawValue = FALSE, includeTotalInfo = FALSE, exportOptions = NULL, showRowGroupHeaders = FALSE )
styleNamePrefix
A character variable specifying a prefix for all named CSS styles, to avoid style name collisions where multiple pivot tables exist.
includeHeaderValues
Default 'FALSE', specify 'TRUE' to render this debug information.
includeRCFilters
Default 'FALSE', specify 'TRUE' to render this debug information.
includeCalculationFilters
Default 'FALSE', specify 'TRUE' to render this debug information.
includeWorkingData
Default 'FALSE', specify 'TRUE' to render this debug information.
includeEvaluationFilters
Default 'FALSE', specify 'TRUE' to render this debug information.
includeCalculationNames
Default 'FALSE', specify 'TRUE' to render this debug information.
includeRawValue
Default 'FALSE', specify 'TRUE' to render this debug information.
includeTotalInfo
Default 'FALSE', specify 'TRUE' to render this debug information.
exportOptions
A list of additional export options - see the "A1. Appendix" for details.
showRowGroupHeaders
Default 'FALSE', specify 'TRUE' to render the row group headings. See the "Data Groups" vignette for details.
A list containing HTML tags from the 'htmltools' package. Convert this to a character variable using 'as.character()'.
clone()
The objects of this class are cloneable with this method.
PivotHtmlRenderer$clone(deep = FALSE)
deep
Whether 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.
# This class should only be created by the pivot table. # It is not intended to be created outside of the pivot table.
The 'PivotLatexRenderer' class creates a Latex representation of a pivot table.
R6Class
object.
new()
Create a new 'PivotLatexRenderer' object.
PivotLatexRenderer$new(parentPivot = NULL)
parentPivot
The pivot table that this 'PivotLatexRenderer' instance belongs to.
A new 'PivotLatexRenderer' object.
clearIsRenderedFlags()
An internal method used when rendering a pivot table to Latex Clear the IsRendered flags that exist on the 'PivotDataGroup' class.
PivotLatexRenderer$clearIsRenderedFlags()
No return value.
resetVisibleRange()
Clears the visible range that has been set, so the next call to 'getTableLatex()' will render the whole table.
PivotLatexRenderer$resetVisibleRange()
No return value.
setVisibleRange()
Specifies a subset of the pivot table to be rendered, e.g. for use when a pivot table will not fit into a single A4 page.
PivotLatexRenderer$setVisibleRange( fromRow = NULL, toRow = NULL, fromColumn = NULL, toColumn = NULL )
fromRow
The row number to render from.
toRow
The row number to render to.
fromColumn
The column number to render from.
toColumn
The column number to render to.
No return value.
getTableLatex()
Generate a Latex representation of the pivot table.
PivotLatexRenderer$getTableLatex( caption = NULL, label = NULL, boldHeadings = FALSE, italicHeadings = FALSE, exportOptions = NULL )
caption
The caption to appear above the table.
label
The label to use when referring to the table elsewhere in the document
boldHeadings
Default 'FALSE', specify 'TRUE' to render headings in bold.
italicHeadings
Default 'FALSE', specify 'TRUE' to render headings in italic.
exportOptions
A list of additional export options - see the "A1. Appendix" for details.
A character variable containing the Latex representation of the pivot table.
clone()
The objects of this class are cloneable with this method.
PivotLatexRenderer$clone(deep = FALSE)
deep
Whether 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.
# This class should only be created by the pivot table. # It is not intended to be created outside of the pivot table.
The 'PivotOpenXlsxRenderer' class creates a representation of a pivot table in an Excel file using the 'openxlsx' package. See the "Excel Export" vignette for details and examples.
R6Class
object.
new()
Create a new 'PivotOpenXlsxRenderer' object.
PivotOpenXlsxRenderer$new(parentPivot)
parentPivot
The pivot table that this 'PivotOpenXlsxRenderer' instance belongs to.
A new 'PivotOpenXlsxRenderer' object. An internal method used when rendering a pivot table to HTML. Clear the IsRendered flags that exist on the 'PivotDataGroup' class.
clearIsRenderedFlags()
PivotOpenXlsxRenderer$clearIsRenderedFlags()
No return value.
writeToCell()
Writes a value to a cell and applies styling as needed.
PivotOpenXlsxRenderer$writeToCell( wb = NULL, wsName = NULL, rowNumber = NULL, columnNumber = NULL, value = NULL, applyStyles = TRUE, baseStyleName = NULL, style = NULL, mapFromCss = TRUE, mergeRows = NULL, mergeColumns = NULL )
wb
A 'Workbook' object representing the Excel file being written to.
wsName
A character value specifying the name of the worksheet to write to.
rowNumber
An integer value specifying the row number of the cell to write to.
columnNumber
An integer value specifying the column number of the cell to write to.
value
The value to write into the cell.
applyStyles
Default 'TRUE' to write styling information to the cell.
baseStyleName
A character value specifying a named style defined in the pivot table.
style
A 'PivotStyle' object containing CSS style declarations to override the base style.
mapFromCss
Default 'TRUE' to automatically convert CSS style declarations to their Excel equivalents.
mergeRows
An integer vector specifying the row extent of a merged cell.
mergeColumns
An integer vector specifying the column extent of a merged cell.
No return value.
writeToWorksheet()
Write the pivot table into the specified workbook and worksheet at the specified row-column location.
PivotOpenXlsxRenderer$writeToWorksheet( wb = NULL, wsName = NULL, topRowNumber = NULL, leftMostColumnNumber = NULL, outputHeadingsAs = "formattedValueAsText", outputValuesAs = "rawValue", applyStyles = TRUE, mapStylesFromCSS = TRUE, exportOptions = NULL, showRowGroupHeaders = FALSE )
wb
A 'Workbook' object representing the Excel file being written to.
wsName
A character value specifying the name of the worksheet to write to.
topRowNumber
An integer value specifying the row number in the Excel worksheet to write the pivot table.
leftMostColumnNumber
An integer value specifying the column number in the Excel worksheet to write the pivot table.
outputHeadingsAs
Must be one of "rawValue", "formattedValueAsText" (default) or "formattedValueAsNumber" to specify how data groups are written into the Excel sheet.
outputValuesAs
Must be one of "rawValue" (default), "formattedValueAsText" or "formattedValueAsNumber" to specify how cell values are written into the Excel sheet.
applyStyles
Default 'TRUE' to write styling information to the cell.
mapStylesFromCSS
Default 'TRUE' to automatically convert CSS style declarations to their Excel equivalents.
exportOptions
A list of additional export options - see the "A1. Appendix" for details.
showRowGroupHeaders
Default 'FALSE', specify 'TRUE' to write row group headers.
No return value.
clone()
The objects of this class are cloneable with this method.
PivotOpenXlsxRenderer$clone(deep = FALSE)
deep
Whether 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.
# This class should only be created by the pivot table. # It is not intended to be created outside of the pivot table.
The 'PivotOpenXlsxStyle' class specifies the styling for cells in an Excel worksheet.
R6Class
object.
baseStyleName
The name of the base style in the pivot table.
isBaseStyle
'TRUE' when this style is the equivalent of a named style in the pivot table, 'FALSE' if this style has additional settings over and above the base style of the same name.
fontName
The name of the font (single font name, not a CSS style list).
fontSize
The size of the font (units: point, 4-72).
bold
'TRUE' if text is bold.
italic
'TRUE' if text is italic.
underline
'TRUE' if text is underlined.
strikethrough
'TRUE' if text has a line through it.
superscript
'TRUE' if text is small and raised.
subscript
'TRUE' if text is small and lowered.
fillColor
The background colour for the cell (as a hex value, e.g. #00FF00).
textColor
The color of the text (as a hex value).
hAlign
The horizontal alignment of the text: left, center or right.
vAlign
The vertical alignment of the text: top, middle or bottom.
wrapText
'TRUE' if the text is allowed to wrap onto multiple lines.
textRotation
The rotation angle of the text (0 to 359) or 255 for vertical.
indent
Horizontal indentation of cell contents (0 to 250.).
borderAll
A list (with elements style and color) specifying the border settings for all four sides of each cell at once.
borderLeft
A list (with elements style and color) specifying the border settings for the left border of each cell.
borderRight
A list (with elements style and color) specifying the border settings for the right border of each cell.
borderTop
A list (with elements style and color) specifying the border settings for the top border of each cell.
borderBottom
A list (with elements style and color) specifying the border settings for the bottom border of each cell.
valueFormat
The Excel formatting applied to the field value. One of the following values: GENERAL, NUMBER, CURRENCY, ACCOUNTING, DATE, LONGDATE, TIME, PERCENTAGE, FRACTION, SCIENTIFIC, TEXT, COMMA. Or for dates/datetimes, a combination of d, m, y. Or for numeric values, use a numeric format code such as 0.00, #,###.00, etc
minColumnWidth
The minimum width of this column (0 to 255).
minRowHeight
The minimum height of this row (0 to 400).
openxlsxStyle
The style object returned from 'openxlsx::createStyle()'.
new()
Create a new 'PivotOpenXlsxStyle' object.
PivotOpenXlsxStyle$new( parentPivot, baseStyleName = NULL, isBaseStyle = NULL, fontName = NULL, fontSize = NULL, bold = NULL, italic = NULL, underline = NULL, strikethrough = NULL, superscript = NULL, subscript = NULL, fillColor = NULL, textColor = NULL, hAlign = NULL, vAlign = NULL, wrapText = NULL, textRotation = NULL, indent = NULL, borderAll = NULL, borderLeft = NULL, borderRight = NULL, borderTop = NULL, borderBottom = NULL, valueFormat = NULL, minColumnWidth = NULL, minRowHeight = NULL )
parentPivot
The pivot table that this 'PivotOpenXlsxStyle' instance belongs to.
baseStyleName
The name of the base style in the pivot table.
isBaseStyle
'TRUE' when this style is the equivalent of a named style in the pivot table, 'FALSE' if this style has additional settings over and above the base style of the same name.
fontName
The name of the font (single font name, not a CSS style list).
fontSize
The size of the font (units: point, 4-72).
bold
'TRUE' if text is bold.
italic
'TRUE' if text is italic.
underline
'TRUE' if text is underlined.
strikethrough
'TRUE' if text has a line through it.
superscript
'TRUE' if text is small and raised.
subscript
'TRUE' if text is small and lowered.
fillColor
The background colour for the cell (as a hex value, e.g. #00FF00).
textColor
The color of the text (as a hex value).
hAlign
The horizontal alignment of the text: left, center or right.
vAlign
The vertical alignment of the text: top, middle or bottom.
wrapText
'TRUE' if the text is allowed to wrap onto multiple lines.
textRotation
The rotation angle of the text (0 to 359) or 255 for vertical.
indent
Horizontal indentation of cell contents (0 to 250.).
borderAll
A list (with elements style and color) specifying the border settings for all four sides of each cell at once.
borderLeft
A list (with elements style and color) specifying the border settings for the left border of each cell.
borderRight
A list (with elements style and color) specifying the border settings for the right border of each cell.
borderTop
A list (with elements style and color) specifying the border settings for the top border of each cell.
borderBottom
A list (with elements style and color) specifying the border settings for the bottom border of each cell.
valueFormat
The Excel formatting applied to the field value. One of the following values: GENERAL, NUMBER, CURRENCY, ACCOUNTING, DATE, LONGDATE, TIME, PERCENTAGE, FRACTION, SCIENTIFIC, TEXT, COMMA. Or for dates/datetimes, a combination of d, m, y. Or for numeric values, use a numeric format code such as 0.00, #,###.00, etc
minColumnWidth
The minimum width of this column (0 to 255).
minRowHeight
The minimum height of this row (0 to 400).
A new 'PivotOpenXlsxStyle' object.
isBasicStyleNameMatch()
Test whether a style is a base style with the specified name.
PivotOpenXlsxStyle$isBasicStyleNameMatch(baseStyleName = NULL)
baseStyleName
The name of the style to match.
No return value.
isFullStyleDetailMatch()
Test whether a style has matching style attributes.
PivotOpenXlsxStyle$isFullStyleDetailMatch( baseStyleName = NULL, isBaseStyle = NULL, fontName = NULL, fontSize = NULL, bold = NULL, italic = NULL, underline = NULL, strikethrough = NULL, superscript = NULL, subscript = NULL, fillColor = NULL, textColor = NULL, hAlign = NULL, vAlign = NULL, wrapText = NULL, textRotation = NULL, indent = NULL, borderAll = NULL, borderLeft = NULL, borderRight = NULL, borderTop = NULL, borderBottom = NULL, valueFormat = NULL, minColumnWidth = NULL, minRowHeight = NULL )
baseStyleName
The name of the base style in the pivot table.
isBaseStyle
'TRUE' when this style is the equivalent of a named style in the pivot table, 'FALSE' if this style has additional settings over and above the base style of the same name.
fontName
The name of the font (single font name, not a CSS style list).
fontSize
The size of the font (units: point, 4-72).
bold
'TRUE' if text is bold.
italic
'TRUE' if text is italic.
underline
'TRUE' if text is underlined.
strikethrough
'TRUE' if text has a line through it.
superscript
'TRUE' if text is small and raised.
subscript
'TRUE' if text is small and lowered.
fillColor
The background colour for the cell (as a hex value, e.g. #00FF00).
textColor
The color of the text (as a hex value).
hAlign
The horizontal alignment of the text: left, center or right.
vAlign
The vertical alignment of the text: top, middle or bottom.
wrapText
'TRUE' if the text is allowed to wrap onto multiple lines.
textRotation
The rotation angle of the text (0 to 359) or 255 for vertical.
indent
Horizontal indentation of cell contents (0 to 250.).
borderAll
A list (with elements style and color) specifying the border settings for all four sides of each cell at once.
borderLeft
A list (with elements style and color) specifying the border settings for the left border of each cell.
borderRight
A list (with elements style and color) specifying the border settings for the right border of each cell.
borderTop
A list (with elements style and color) specifying the border settings for the top border of each cell.
borderBottom
A list (with elements style and color) specifying the border settings for the bottom border of each cell.
valueFormat
The Excel formatting applied to the field value. One of the following values: GENERAL, NUMBER, CURRENCY, ACCOUNTING, DATE, LONGDATE, TIME, PERCENTAGE, FRACTION, SCIENTIFIC, TEXT, COMMA. Or for dates/datetimes, a combination of d, m, y. Or for numeric values, use a numeric format code such as 0.00, #,###.00, etc
minColumnWidth
The minimum width of this column (0 to 255).
minRowHeight
The minimum height of this row (0 to 400).
Base styles are compared on name only, otherwise the style attributes are compared.
No return value.
createOpenXslxStyle()
Create an 'openxlsx' style from this style definition.
PivotOpenXlsxStyle$createOpenXslxStyle()
No return value. Retrieve the style using the 'openxlsxStyle' property.
asList()
Return the contents of this object as a list for debugging.
PivotOpenXlsxStyle$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
PivotOpenXlsxStyle$asJSON()
A JSON representation of various object properties.
asString()
Return a representation of this object as a character value.
PivotOpenXlsxStyle$asString()
A character summary of various object properties.
clone()
The objects of this class are cloneable with this method.
PivotOpenXlsxStyle$clone(deep = FALSE)
deep
Whether to make a deep clone.
# PivotOpenXlsxStyle objects are created by the PivotOpenXlsxRenderer class. # See that class for details.
# PivotOpenXlsxStyle objects are created by the PivotOpenXlsxRenderer class. # See that class for details.
The 'PivotOpenXlsxStyles' class stores a collection of 'PivotOpenXlsxStyle' style objects.
R6Class
object.
count
The number of 'PivotOpenXlsxStyle' objects in this 'PivotOpenXlsxStyles' collection.
styles
A list containing the 'PivotOpenXlsxStyle' objects in this 'PivotOpenXlsxStyles' collection.
new()
Create a new 'PivotOpenXlsxStyles' object.
PivotOpenXlsxStyles$new(parentPivot)
parentPivot
The pivot table that this 'PivotOpenXlsxStyles' instance belongs to.
A new 'PivotOpenXlsxStyles' object.
clearStyles()
Clear the internal list of styles.
PivotOpenXlsxStyles$clearStyles()
No return value.
findNamedStyle()
Find an existing openxlsx style matching the name of a base style.
PivotOpenXlsxStyles$findNamedStyle(baseStyleName)
baseStyleName
The name of the base style to find.
A 'PivotOpenXlsxStyle' object with the specified name.
findOrAddStyle()
Find an existing openxlsx style, add a new openxlsx style matching a base style and/or existing 'PivotStyle' object.
PivotOpenXlsxStyles$findOrAddStyle( action = "findOrAdd", baseStyleName = NULL, isBaseStyle = NULL, style = NULL, mapFromCss = TRUE )
action
Must be one of "find" (to search for an existing style), "add" (to add a new style) or "findOrAdd" (default, to first search for an existing style, and if no match is found then add a new style)
baseStyleName
The name of the base style to find.
isBaseStyle
'TRUE' if the style being sought is a base style.
style
An existing 'PivotStyle' object.
mapFromCss
Default 'TRUE', to create a new 'PivotOpenXlsxStyle' by mapping from CSS style declarations.
This function is used in two different ways: (1) When adding base styles (i.e. named styles in the pivot table) to this 'PivotOpenXlsxStyles' collection: In this case, 'baseStyleName' is the name of the style and 'isBaseStyle=TRUE' (so matching is by name only) and 'style' is the 'PivotStyle' object for the base style. (2) When finding styles that have been applied to individual cells using the 'PivotStyle' object that is attached to each cell: In this case, 'baseStyleName' may or may not be present, 'isBaseStyle=FALSE' and 'style' is the 'PivotStyle' object from the cell.
A 'PivotOpenXlsxStyle' object that has been found or added.
addNamedStyles()
Populate the OpenXlsx styles based on the styles defined in the pivot table.
PivotOpenXlsxStyles$addNamedStyles(mapFromCss = TRUE)
mapFromCss
Default 'TRUE', to create a new 'PivotOpenXlsxStyle' by mapping from CSS style declarations.
No return value.
asList()
Return the contents of this object as a list for debugging.
PivotOpenXlsxStyles$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
PivotOpenXlsxStyles$asJSON()
A JSON representation of various object properties.
asString()
Return a representation of this object as a character value.
PivotOpenXlsxStyles$asString(seperator = ", ")
seperator
A character value used when concatenating multiple styles.
A character summary of various object properties.
clone()
The objects of this class are cloneable with this method.
PivotOpenXlsxStyles$clone(deep = FALSE)
deep
Whether 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.
# This class should only be created by the pivot table. # It is not intended to be created outside of the pivot table.
The 'PivotStyle' class specifies the styling for headers and cells in a pivot table. Styles are specified in the form of Cascading Style Sheet (CSS) name-value pairs.
R6Class
object.
name
The name of the style (for a named style).
declarations
A list containing the style declarations.
new()
Create a new 'PivotStyle' object.
PivotStyle$new(parentPivot, styleName = NULL, declarations = NULL)
parentPivot
The pivot table that this 'PivotStyle' instance belongs to.
styleName
The name of the style (for a named style).
declarations
CSS style declarations in the form of a list, e.g. 'list("font-weight"="bold", "color"="#0000FF")'
A new 'PivotStyle' object.
setPropertyValue()
Set a single style property.
PivotStyle$setPropertyValue(property = NULL, value = NULL)
property
The name of the style property to set, e.g. "font-weight".
value
The value of the style property to set, e.g. "bold".
No return value.
setPropertyValues()
Set multiple style properties.
PivotStyle$setPropertyValues(declarations = NULL)
declarations
CSS style declarations in the form of a list, e.g. 'list("font-weight"="bold", "color"="#0000FF")'
No return value.
getPropertyValue()
Get the value of a single style property.
PivotStyle$getPropertyValue(property = NULL)
property
The name of the style property to set, e.g. "font-weight".
The value of the style property.
asCSSRule()
Get the style definition in the form of a CSS rule.
PivotStyle$asCSSRule(selector = NULL)
selector
A CSS selector, used to select the element(s) to be styled.
The style declarations in the form of a CSS rule, i.e. selector property-name1: property-value1, property-name2: property-value2, ... e.g. div font-weight: bold, color: #0000FF
asNamedCSSStyle()
Get the style definition in the form of a named CSS style.
PivotStyle$asNamedCSSStyle(styleNamePrefix = NULL)
styleNamePrefix
A prefix to prepend to the style name.
The style declarations in the form of named CSS style, i.e. .prefix-stylename property-name1: property-value1, property-name2: property-value2, ... e.g. .pvt1Cell font-weight: bold, color: #0000FF
getCopy()
Create a copy of this 'PivotStyle' object.
PivotStyle$getCopy(newStyleName = NULL)
newStyleName
The name of the new style.
A 'PivotStyle' object.
asList()
Return the contents of this object as a list for debugging.
PivotStyle$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
PivotStyle$asJSON()
A JSON representation of various object properties.
clone()
The objects of this class are cloneable with this method.
PivotStyle$clone(deep = FALSE)
deep
Whether 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.
# This class should only be created by the pivot table. # It is not intended to be created outside of the pivot table.
The 'PivotStyles' class is a collection of 'PivotStyle' objects. It defines all of the base styles needed to style/theme a pivot table. It also defines the names of the styles that are used for styling the different parts of the pivot table.
R6Class
object.
count
The number of 'PivotStyle' objects in this 'PivotStyles' collection.
theme
A theme name to represent this collection of styles.
styles
A list containing the 'PivotStyle' objects in this 'PivotStyles' collection.
allowExternalStyles
Default 'FALSE', which means this 'PivotStyles' object checks that style names specified for styling the different parts of the pivot table must exist in the styles collection. If they do not an error will occur. Specify 'TRUE' to disable this check, e.g. if the style definitions are not managed by 'pivottabler' but instead in an external system.
tableStyle
The name of the style for the HTML table element.
rootStyle
The name of the style for the HTML cell at the top left of the pivot table.
rowHeaderStyle
The name of the style for the row headers in the pivot table.
colHeaderStyle
The name of the style for the column headers in the pivot table.
outlineRowHeaderStyle
The name of the style for the outline row headers in the pivot table.
outlineColHeaderStyle
The name of the style for the outline column headers in the pivot table.
cellStyle
The name of the cell style for the non-total cells in the body of the pivot table.
outlineCellStyle
The name of the cell style for the non-total outline cells in the body of the pivot table.
totalStyle
The name of the cell style for the total cells in the pivot table.
new()
Create a new 'PivotStyles' object.
PivotStyles$new(parentPivot, themeName = NULL, allowExternalStyles = FALSE)
parentPivot
The pivot table that this 'PivotStyles' instance belongs to.
themeName
A theme name to represent this collection of styles.
allowExternalStyles
Default 'FALSE', which means this 'PivotStyles' object checks that style names specified for styling the different parts of the pivot table must exist in the styles collection. If they do not an error will occur. Specify 'TRUE' to disable this check, e.g. if the style definitions are not managed by 'pivottabler' but instead in an external system.
A new 'PivotStyles' object.
isExistingStyle()
Check whether a style with the specified style name exists in the collection.
PivotStyles$isExistingStyle(styleName = NULL)
styleName
The name of the style.
'TRUE' if a style with the specified name exists, 'FALSE' otherwise.
getStyle()
Retrieve a style with the specified style name.
PivotStyles$getStyle(styleName = NULL)
styleName
The name of the style.
A 'PivotStyle' object.
addStyle()
Add a new style to the collection of styles.
PivotStyles$addStyle(styleName = NULL, declarations = NULL)
styleName
The name of the new style.
declarations
CSS style declarations in the form of a list, e.g. 'list("font-weight"="bold", "color"="#0000FF")'
The newly created 'PivotStyle' object.
copyStyle()
Create a copy of a style with the specified name and store it in the collection.
PivotStyles$copyStyle(styleName = NULL, newStyleName = NULL)
styleName
The name of the style to copy.
newStyleName
The name for the new style.
The newly created 'PivotStyle' object.
asCSSRule()
Get a style definition in the form of a CSS rule.
PivotStyles$asCSSRule(styleName = NULL, selector = NULL)
styleName
The name of the style.
selector
A CSS selector, used to select the element(s) to be styled.
The style declarations in the form of a CSS rule, i.e. selector property-name1: property-value1, property-name2: property-value2, ... e.g. div font-weight: bold, color: #0000FF
asNamedCSSStyle()
Get a style definition in the form of a named CSS style.
PivotStyles$asNamedCSSStyle(styleName = NULL, styleNamePrefix = NULL)
styleName
The name of the style.
styleNamePrefix
A prefix to prepend to the style name.
The style declarations in the form of named CSS style, i.e. .prefix-stylename property-name1: property-value1, property-name2: property-value2, ... e.g. .pvt1Cell font-weight: bold, color: #0000FF
asList()
Return the contents of this object as a list for debugging.
PivotStyles$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
PivotStyles$asJSON()
A JSON representation of various object properties.
asString()
Return a representation of this object as a character value.
PivotStyles$asString(seperator = ", ")
seperator
A character value to use when concatenating multiple styles.
A character summary of various object properties.
clone()
The objects of this class are cloneable with this method.
PivotStyles$clone(deep = FALSE)
deep
Whether to make a deep clone.
pt <- PivotTable$new() # ... pivotStyles <- PivotStyles$new(pt, themeName="compact") pivotStyles$addStyle(styleName="MyNewStyle", list( font="0.75em arial", padding="2px", border="1px solid lightgray", "vertical-align"="middle", "text-align"="center", "font-weight"="bold", "background-color"="#F2F2F2" ))
pt <- PivotTable$new() # ... pivotStyles <- PivotStyles$new(pt, themeName="compact") pivotStyles$addStyle(styleName="MyNewStyle", list( font="0.75em arial", padding="2px", border="1px solid lightgray", "vertical-align"="middle", "text-align"="center", "font-weight"="bold", "background-color"="#F2F2F2" ))
The 'PivotTable' class is the primary class for constructing and interacting with a pivot table.
R6Class
object.
argumentCheckMode
The level of argument checking to perform. One of "auto", "none", "minimal", "basic", "balanced" (default) or "full".
compatibility
A list containing compatibility options to force legacy behaviours. See the NEWS file for details.
traceEnabled
Default 'FALSE'. Specify 'TRUE' to generate a trace for debugging purposes.
processingLibrary
The package to use when processing data. Must be one of "auto" (which today is dplyr), "dplyr" or "data.table".
data
A 'PivotData' object containing the data frames added to the pivot table.
rowGroup
The hidden root 'PivotDataGroup' at the top of the row data groups hierarchy. The children of this group form the first level of visible row data groups.
columnGroup
The hidden root 'PivotDataGroup' at the top of the column data groups hierarchy. The children of this group form the first level of visible column data groups.
rowGroupLevelCount
The number of visible levels in the row data group hierarchy.
columnGroupLevelCount
The number of visible levels in the column data group hierarchy.
topColumnGroups
A list containing the first level of column data groups.
leafColumnGroups
A list containing the bottom level of column data groups.
allColumnGroups
A list containing all of the column data groups.
topRowGroups
A list containing the first level of row data groups.
leafRowGroups
A list containing the bottom level of row data groups.
allRowGroups
A list containing all of the row data groups.
rowGrpHeaders
A list containing the row group headers.
calculationGroups
A list containing the calculation groups in the pivot table.
calculationsPosition
Either "row" or "column" describing which axis the calculations are rendered.
evaluationMode
Either "batch" (default) or "sequential" (legacy).
batchInfo
Diagnostic information describing the batches used in the last pivot table evaluation.
cells
A 'PivotCells' object that contains all of the cells in the pivot table.
allCells
A list of all of the cells in the pivot table, where each element in the list is a 'PivotCell' object.
rowCount
The number of rows in the pivot table, excluding headings.
columnCount
The number of columns in the pivot table, excluding headings.
fixedWidthSized
The total width of the pivot table in characters if the pivot table were to be rendered as plain text, e.g. to the console.
asCharacter
A plain text representation of the pivot table.
theme
The name of the theme used to style the pivot table. If setting this property, either a theme name can be used, or a list can be used (which specifies a simple theme) or a 'PivotStyles' object can be used. See the "Styling" vignette for details and examples.
styles
A 'PivotStyles' object that contains the styles applied to the pivot table.
allowExternalStyles
Default 'FALSE', which means the 'PivotStyles' object checks that style names specified for styling the different parts of the pivot table must exist in the styles collection. If they do not an error will occur. Specify 'TRUE' to disable this check, e.g. if the style definitions are not managed by 'pivottabler' but instead in an external system.
mergeEmptyRowSpace
A character value describing how empty space is merged. Allowed values: "doNotMerge", "dataGroupsOnly", "cellsOnly", "dataGroupsAndCellsAs1", "dataGroupsAndCellsAs2".
mergeEmptyColumnSpace
A character value describing how empty space is merged. Allowed values: "doNotMerge", "dataGroupsOnly", "cellsOnly", "dataGroupsAndCellsAs1", "dataGroupsAndCellsAs2".
mergeEmptySpaceDirection
A character value describing how empty space is merged. Allowed values: "row" or "column"
allTimings
Get a data frame containing timing details of pivot table operations.
significantTimings
Get a data frame containing timing details of significant pivot table operations (i.e. where elapsed>0.1).
new()
Create a new 'PivotTable' object.
PivotTable$new( processingLibrary = "auto", evaluationMode = "batch", argumentCheckMode = "auto", theme = NULL, replaceExistingStyles = FALSE, tableStyle = NULL, headingStyle = NULL, cellStyle = NULL, totalStyle = NULL, compatibility = NULL, traceEnabled = FALSE, traceFile = NULL )
processingLibrary
The package to use when processing data. Must be one of "auto" (which today is dplyr), "dplyr" or "data.table".
evaluationMode
Either "batch" (default) or "sequential" (legacy).
argumentCheckMode
The level of argument checking to perform. Must be one of "auto", "none", "minimal", "basic", "balanced" (default) or "full".
theme
A theme to use to style the pivot table. Either:
(1) The name of a built in theme, or
(2) A list of simple style settings, or
(3) A 'PivotStyles' object containing a full set of styles.
See the "Styling" vignette for many examples.
replaceExistingStyles
Default 'FALSE' to retain existing styles in the styles collection and add specified styles as new custom styles. Specify 'TRUE' to update the definitions of existing styles.
tableStyle
Styling to apply to the table. Either:
(1) The name of a built in style, or
(2) A list of CSS style declarations, e.g.
'list("font-weight"="bold", "color"="#0000FF")', or
(3) A 'PivotStyle' object.
headingStyle
Styling to apply to the headings. See the 'tableStyle' argument for details.
cellStyle
Styling to apply to the normal cells. See the 'tableStyle' argument for details.
totalStyle
Styling to apply to the total cells. See the 'tableStyle' argument for details.
compatibility
A list containing compatibility options to force legacy behaviours. See the NEWS file for details.
traceEnabled
Default 'FALSE'. Specify 'TRUE' to generate a trace for debugging purposes.
traceFile
If tracing is enabled, the location to generate the trace file.
A new 'PivotTable' object.
setDefault()
Specify default values for some function arguments.
PivotTable$setDefault(...)
...
Default values to specify. See details.
Defaults can be set for the following arguments of
'pt$addRowDataGroups()' and 'pt$addColumnDataGroups()':
'logical' values: 'addTotal', 'expandExistingTotals', 'visualTotals'.
'character' values: 'totalPosition', 'totalCaption'.
'list' or 'logical' values: 'outlineBefore', 'outlineAfter', 'outlineTotal'.
Errors are generated for default values that could not be set.
Warnings are generated for attempts to set defaults that aren't supported.
See the "A1. Appendix" vignette for more details.
No return value.
getDefault1()
Get the default value of an argument.
PivotTable$getDefault1(argValue = NULL, useDefault = NULL)
argValue
The name and value of the argument.
useDefault
Specify 'TRUE' to use the default.
Both the argument name and argument value are taken from the 'argValue' argument. The name is obtained from 'as.character(substitute(argValue))'. This function is designed to easily slot into existing code, e.g. 'getDefault1(addTotal, missing(addTotal))'.
The current value of the argument or the default value.
getDefault2()
Get the default value of an argument.
PivotTable$getDefault2(argName = NULL, argValue = NULL, useDefault = NULL)
argName
The name of the argument.
argValue
The current value of the argument.
useDefault
Specify 'TRUE' to use the default.
The current value of the argument or the default value.
getDefault3()
Get the default value of an argument.
PivotTable$getDefault3(argName)
argName
The name of the argument.
The default value.
getNextInstanceId()
Get the next unique object instance identifier.
PivotTable$getNextInstanceId()
R6 classes cannot be easily compared to check if two variables are both referring to the same object instance. Instance ids are a mechanism to work around this problem. Each data group and cell is assigned an instance id during object creation, which enables reliable reference comparisons.
An integer instance id.
addData()
Add a data frame with the specified name to the pivot table.
PivotTable$addData(dataFrame = NULL, dataName = NULL)
dataFrame
The data frame to add.
dataName
The name to be used to refer to the data frame. If no name is specified, the data frame variable name from the calling code is used, retrieved via 'deparse(substitute(dataFrame))'.
The name is used to refer to the data frame when generating data groups or defining calculations. The pivot table tracks the first data frame added as the default data frame, so if only a single data frame is used, it is typically not necessary to ever explicitly refer to the name. Pivot tables are typically based on a single data frame, however it is possible to build a pivot table that uses data from multiple data frames.
The 'PivotData' object managing the data frames for the pivot table.
addTotalData()
Add a data frame containing totals data with the specified name and variables to the pivot table.
PivotTable$addTotalData( dataFrame = NULL, dataName = NULL, variableNames = NULL )
dataFrame
The data frame to add.
dataName
The name of the data frame to associate these totals with.
variableNames
A vector specifying how the aggregate data/totals in the data frame are grouped.
When generating pivot tables, the package typically calculates cell values. However, the package can also use provided values (i.e. carry out no calculations). This presents a challenge in that the sub-totals and totals in a pivot table display values at a higher aggregation level than the normal cells in the body of the pivot table. This method allows further data frames to be specified that contain aggregated versions of the data. See the "Calculations" vignette for details and an example.
No return value.
getColumnGroupsByLevel()
Retrieve the data groups at the specified level or levels in the column groups hierarchy.
PivotTable$getColumnGroupsByLevel(level = NULL, collapse = FALSE)
level
An integer value or vector specifying one or more level numbers. Level 1 represents the first visible level of data groups.
collapse
A logical value specifying whether the return value should be simplified. See details.
If 'level' is a vector: If 'collapse' is 'FALSE', then a list of lists is returned, if 'collapse' is 'TRUE', then a single combined list is returned.
A list containing 'PivotDataGroup' objects.
getTopColumnGroups()
[Deprecated: Use topColumnGroups instead] Retrieve the first level of column data groups.
PivotTable$getTopColumnGroups()
A list containing 'PivotDataGroup' objects.
getLeafColumnGroups()
[Deprecated: Use leafColumnGroups instead] Retrieve the bottom level of column data groups.
PivotTable$getLeafColumnGroups()
A list containing 'PivotDataGroup' objects.
getLeafColumnGroup()
Retrieve the leaf-level data group associated with a specific column or columns.
PivotTable$getLeafColumnGroup(c = NULL)
c
An integer column number or an integer vector of column numbers.
A 'PivotDataGroup' object or a list of 'PivotDataGroup' objects.
addColumnGroup()
Add a new column data group at the top level of the column group hierarchy. The new group is added as the last child unless an index is specified.
PivotTable$addColumnGroup( 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, 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".
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.
See the "Irregular Layout" vignette for details and examples.
The new 'PivotDataGroup' object.
addColumnDataGroups()
Add multiple new data groups to the column group hierarchy based on the distinct values in a data frame column or using explicitly specified data values. See the "Data Groups" vignette for example usage.
PivotTable$addColumnDataGroups( 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 )
variableName
The name of the related column in the data frame(s) of the pivot table.
atLevel
The level number that specifies where to add the new groups. Level 1 = on the first visible level of the hierarchy. '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")'.
There are broadly three different ways to call 'addColumnDataGroups()':
(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.
A list of new 'PivotDataGroup' objects that have been added.
normaliseColumnGroups()
Normalise the column data group hierarchy so that all branches have the same number of levels - accomplished by adding empty child data groups where needed.
PivotTable$normaliseColumnGroups(resetCells = TRUE)
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.
A list of new 'PivotDataGroup' objects that have been added.
sortColumnDataGroups()
Sort column data groups either by the data group data value, caption, a custom order or based on calculation result values.
PivotTable$sortColumnDataGroups( levelNumber = 1, orderBy = "calculation", customOrder = NULL, sortOrder = "desc", calculationGroupName = "default", calculationName = NULL, fromIndex = NULL, toIndex = NULL, resetCells = TRUE )
levelNumber
The level number to sort the data groups, e.g. level 1 (default) sorts the data groups at level 1 of the hierarchy (which is the first visible level of data groups).
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.
No return value.
getRowGroupsByLevel()
Retrieve the data groups at the specified level or levels in the row groups hierarchy.
PivotTable$getRowGroupsByLevel(level = NULL, collapse = FALSE)
level
An integer value or vector specifying one or more level numbers. Level 1 represents the first visible level of data groups.
collapse
A logical value specifying whether the return value should be simplified. See details.
If 'level' is a vector: If 'collapse' is 'FALSE', then a list of lists is returned, if 'collapse' is 'TRUE', then a single combined list is returned.
A list containing 'PivotDataGroup' objects.
getTopRowGroups()
[Deprecated: Use topRowGroups instead] Retrieve the first level of row data groups.
PivotTable$getTopRowGroups()
A list containing 'PivotDataGroup' objects.
getLeafRowGroups()
[Deprecated: Use leafRowGroups instead] Retrieve the bottom level of row data groups.
PivotTable$getLeafRowGroups()
A list containing 'PivotDataGroup' objects.
getLeafRowGroup()
Retrieve the leaf-level data group associated with a specific row or rows.
PivotTable$getLeafRowGroup(r = NULL)
r
An integer row number or an integer vector of row numbers.
A 'PivotDataGroup' object or a list of 'PivotDataGroup' objects.
addRowGroup()
Add a new column data group at the top level of the row group hierarchy. The new group is added as the last child unless an index is specified.
PivotTable$addRowGroup( 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, 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".
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.
outlineLinkedGroupId
Used to link an outline group to the value data group which has the child data groups.
See the "Irregular Layout" vignette for details and examples.
The new 'PivotDataGroup' object.
addRowDataGroups()
Add multiple new data groups to the row group hierarchy based on the distinct values in a data frame column or using explicitly specified data values. See the "Data Groups" vignette for example usage.
PivotTable$addRowDataGroups( 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, header = NULL, outlineBefore = NULL, outlineAfter = NULL, outlineTotal = NULL, onlyAddOutlineChildGroupIf = NULL )
variableName
The name of the related column in the data frame(s) of the pivot table.
atLevel
The level number that specifies where to add the new groups. Level 1 = on the first visible level of the hierarchy. '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")'.
header
A character value used as the row-group column caption when row group headers are rendered.
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 'addRowDataGroups()':
(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.
A list of new 'PivotDataGroup' objects that have been added.
normaliseRowGroups()
Normalise the row data group hierarchy so that all branches have the same number of levels - accomplished by adding empty child data groups where needed.
PivotTable$normaliseRowGroups(resetCells = TRUE)
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.
A list of new 'PivotDataGroup' objects that have been added.
sortRowDataGroups()
Sort row data groups either by the data group data value, caption, a custom order or based on calculation result values.
PivotTable$sortRowDataGroups( levelNumber = 1, orderBy = "calculation", customOrder = NULL, sortOrder = "desc", calculationGroupName = "default", calculationName = NULL, fromIndex = NULL, toIndex = NULL, resetCells = TRUE )
levelNumber
The level number to sort the data groups, e.g. level 1 (default) sorts the data groups at level 1 of the hierarchy (which is the first visible level of data groups).
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.
No return value.
setRowDataGroupHeader()
Set the row group header associated with a level of the row data group hierarchy.
PivotTable$setRowDataGroupHeader(levelNumber = NULL, header = NULL)
levelNumber
An integer specifying the level number.
header
A character value specifying the caption.
By default, the row data groups (i.e. row headings) at the left of the pivot table have no column headings. This method can specify the headings, which can be rendered by specifying the 'showRowGroupHeaders=TRUE' in the render methods.
No return value.
addCalculationGroup()
Create a new calculation group. This is rarely needed since the default group is sufficient for all regular pivot tables.
PivotTable$addCalculationGroup(calculationGroupName = NULL)
calculationGroupName
The name of the new calculation group to create.
A 'PivotCalculationGroup' object.
defineCalculation()
Create a new 'PivotCalculation' object.
PivotTable$defineCalculation( calculationGroupName = "default", 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, resetCells = TRUE )
calculationGroupName
The name of the calculation group this calculation will belong to. The default calculation group will be used if this parameter is not specified (this is sufficient for all regular pivot tables).
calculationName
Calculation unique name.
caption
Calculation 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.
displayOrder
The order the calculations are displayed in the pivot table.
filters
Any 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.
format
A character, list or custom function to format the calculation result.
fmtFuncArgs
A list that specifies any additional arguments to pass to a custom format function.
dataName
Specifies which data frame in the pivot table is used for this calculation (as specified in 'pt$addData()').
type
The calculation type: "summary", "calculation", "function" or "value".
valueName
For type="value", the name of the column containing the value to display in the pivot table.
summariseExpression
For type="summary", either the dplyr expression to use with dplyr::summarise() or a data.table calculation expression.
calculationExpression
For type="calculation", an expression to combine aggregate values.
calculationFunction
For type="function", a reference to a custom R function that will carry out the calculation.
calcFuncArgs
For type="function", a list that specifies additional arguments to pass to calculationFunction.
basedOn
A character vector specifying the names of one or more calculations that this calculation depends on.
noDataValue
An integer or numeric value specifying the value to use if no data exists for a particular cell.
noDataCaption
A character value that will be displayed by the pivot table if no data exists for a particular cell.
headingBaseStyleName
The name of a style defined in the pivot table to use as the base styling for the data group heading.
headingStyleDeclarations
A list of CSS style declarations (e.g. 'list("font-weight"="bold")') to override the base style.
cellBaseStyleName
The name of a style defined in the pivot table to use as the base styling for the cells related to this calculation.
cellStyleDeclarations
A list of CSS style declarations (e.g. 'list("font-weight"="bold")') to override the base style.
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.
A new 'PivotCalculation' object.
addColumnCalculationGroups()
Set calculations on existing data groups or add multiple new groups to the column data group hierarchy to represent calculations.
PivotTable$addColumnCalculationGroups( calculationGroupName = "default", atLevel = NULL )
calculationGroupName
The name of the calculation group to add into the data group hierarchy.
atLevel
The level number that specifies where to add the new groups. Level 1 = on the first visible level of the hierarchy. 'NULL' = create a new level at the bottom of the hierarchy for the new groups.
If only one calculation is defined in the pivot table, then the calculation is set onto the existing column data groups (and no new groups are generated). If multiple calculations are defined, then a new level of data groups is added, e.g. if two calculations are defined, then two new data groups will be created under each existing leaf-level column data group.
A list of new 'PivotDataGroup' objects that have been added.
addRowCalculationGroups()
Set calculations on existing data groups or add multiple new groups to the row data group hierarchy to represent calculations.
PivotTable$addRowCalculationGroups( calculationGroupName = "default", atLevel = NULL, outlineBefore = NULL, outlineAfter = NULL )
calculationGroupName
The name of the calculation group to add into the data group hierarchy.
atLevel
The level number that specifies where to add the new groups. Level 1 = on the first visible level of the hierarchy. '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.
If only one calculation is defined in the pivot table, then the calculation is set onto the existing row data groups (and no new groups are generated). If multiple calculations are defined, then a new level of data groups is added, e.g. if two calculations are defined, then two new data groups will be created under each existing leaf-level row data group.
A list of new 'PivotDataGroup' objects that have been added.
addStyle()
Add a new named style to the pivot table.
PivotTable$addStyle(styleName = NULL, declarations = NULL)
styleName
The name of the new style.
declarations
CSS style declarations in the form of a list, e.g. 'list("font-weight"="bold", "color"="#0000FF")'
The newly created 'PivotStyle' object.
createInlineStyle()
Create an inline style that can be used to override a base style. For general use cases, the 'setStyling()' method provides a simpler and more direct way of styling specific parts of a pivot table.
PivotTable$createInlineStyle(baseStyleName = NULL, declarations = NULL)
baseStyleName
The name of an existing style to base the new style on.
declarations
CSS style declarations in the form of a list, e.g. 'list("font-weight"="bold", "color"="#0000FF")'
Inline styles are typically used to override the style of some specific cells in a pivot table. Inline styles have no name. In HTML, they are rendered as 'style' attributes on specific table cells, where as named styles are linked to cells using the 'class' attribute.
The newly created 'PivotStyle' object.
setStyling()
Apply styling to a set of data groups or cells in a pivot table.
PivotTable$setStyling( rFrom = NULL, cFrom = NULL, rTo = NULL, cTo = NULL, rowNumbers = NULL, columnNumbers = NULL, groups = NULL, cells = NULL, baseStyleName = NULL, style = NULL, declarations = NULL, applyBorderToAdjacentCells = FALSE )
rFrom
An integer row number that specifies the start row for the styling changes.
cFrom
An integer column number that specifies the start column for the styling changes.
rTo
An integer row number that specifies the end row for the styling changes.
cTo
An integer column number that specifies the end column for the styling changes.
rowNumbers
An integer vector that specifies the row numbers for the styling changes.
columnNumbers
An integer vector that specifies the column numbers for the styling changes.
groups
A list containing 'PivotDataGroup' objects.
cells
A list containing 'PivotCell' objects.
baseStyleName
The name of a style to apply.
style
A 'PivotStyle' object to apply.
declarations
CSS style declarations to apply in the form of a list, e.g. 'list("font-weight"="bold", "color"="#0000FF")'
applyBorderToAdjacentCells
TRUE to override the border in neighbouring cells, e.g. the left border of the current cell becomes the right border of the cell to the left. Does not apply to row/column groups.
There are five ways to specify the part(s) of a pivot table to apply
styling to:
(1) By specifying a list of data groups using the 'groups' argument.
(2) By specifying a list of cells using the 'cells' argument.
(3) By specifying a single cell using the 'rFrom' and 'cFrom' arguments.
(4) By specifying a rectangular cell range using the 'rFrom', 'cFrom',
'rTo' and 'cTo' arguments.
(5) By specifying a vector of rowNumbers and/or columnNumbers. If both
rowNumbers and columnNumbers are specified, then the cells at the
intersection of the specified row numbers and column numbers are styled.
If both rFrom/rTo and rowNumbers are specified, then rFrom/rTo constrain
the row numbers specified in rowNumbers.
If both cFrom/cTo and columnNumbers are specified, then cFrom/cTo constrain
the column numbers specified in columnNumbers.
See the "Styling" and "Finding and Formatting" vignettes for more
information and many examples.
No return value.
mapStyling()
Apply styling to pivot table cells based on the value of each cell.
PivotTable$mapStyling( styleProperty = NULL, cells = NULL, valueType = "text", mapType = "range", mappings = NULL, styleLowerValues = FALSE, styleHigherValues = TRUE )
styleProperty
The name of the style property to set on the specified cells, e.g. background-color.
cells
A list containing 'PivotCell' objects.
valueType
The type of style value to be set. Must be one of:
"text", "character", "number", "numeric", "color" or "colour".
"text" and "character" are equivalent. "number" and "numeric" are equivalent.
"color" and "colour" are equivalent.
mapType
The type of mapping to be performed. The following mapping
types are supported:
(1) "value" = a 1:1 mapping which maps each specified "from" value to the
corresponding "to" value, e.g. 100 -> "green".
(2) "logic" = each from value is logical criteria. See details.
(3) "range" = values between each pair of "from" values are mapped to the
corresponding "to" value, e.g. values in the range 80-100 -> "green" (more
specifically values greater than or equal to 80 and less than 100).
(4) "continuous" = rescales values between each pair of "from" values into
the range of the corresponding pair of "to" values, e.g. if the "from" range
is 80-100 and the corresponding "to" range is 0.8-1, then 90 -> 0.9.
"continuous" cannot be used with valueType="text"/"character".
mappings
The mappings to be applied, specified in one of the following
three forms:
(1) a list containing pairs of values, e.g.
'list(0, "red", 0.4, "yellow", 0.8, "green")'.
(2) a list containing "from" and "to" vectors/lists, e.g.
'list(from=c(0, 0.4, 0.8), to=c("red", "yellow", "green"))'.
(3) a custom mapping function that will be invoked once per cell, e.g.
'function(v, cell) if(isTRUE(v>0.8)) return("green") '.
Mappings must be specified in ascending order when valueType="range" or
valueType="continuous".
If a custom mapping function is specified, then the valueType and mapType
parameters are ignored.
styleLowerValues
A logical value, default 'FALSE', that specifies whether values less than the lowest specified "from" value should be styled using the style specified for the lowest "from" value. Only applies when valueType="range" or valueType="continuous".
styleHigherValues
A logical value, default 'TRUE', that specifies whether values greater than the highest specified "from" value should be styled using the style specified for the highest "from" value. Only applies when valueType="range" or valueType="continuous".
'mapStyling()' is typically used to conditionally apply styling to cells
based on the value of each individual cell, e.g. cells with values less
than a specified number could be coloured red.
mapType="logic" maps values matching specified logical criteria to
specific "to" values. The logical criteria can be any of the following
forms (the first matching mapping is used):
(1) a specific value, e.g. 12.
(2) a specific value equality condition, e.g. "v==12", where v
represents the cell value.
(3) a value range expression using the following abbreviated form:
"value1<=v<value2", e.g. "10<=v<15". Only "<" or "<=" can be used
in these value range expressions.
(4) a standard R logical expression, e.g.
"10<=v && v<15".
Basic R functions that test the value can also be
used, e.g. is.na(v).
See the "Styling" and Finding and Formatting" vignettes for more
information and many examples.
No return value.
generateCellStructure()
Generate the cells that will form the body of the pivot table.
PivotTable$generateCellStructure()
This method rarely needs to be called explicitly, since other methods will invoke it if needed.
No return value.
resetCells()
Clear the cells of the pivot table.
PivotTable$resetCells()
The cells are reset automatically when structural changes are made to the pivot table, so this method rarely needs to be called explicitly.
No return value.
evaluateCells()
Calculate the cell values in the body of the pivot table.
PivotTable$evaluateCells()
This method rarely needs to be called explicitly, since other methods will invoke it if needed.
No return value.
evaluatePivot()
Calculate the cell values in the body of the pivot table.
PivotTable$evaluatePivot()
This generally only needs to be called explicitly if specific pivot cells
need to be further processed (e.g. formatted) before the pivot table is
rendered.
This method is a wrapper for calling 'normaliseColumnGroups()',
'normaliseRowGroups()', 'generateCellStructure()' and 'evaluateCells()'
in sequence.
No return value.
findRowDataGroups()
Find row data groups that match specified criteria.
PivotTable$findRowDataGroups( matchMode = "simple", variableNames = NULL, variableValues = NULL, totals = "include", calculationNames = NULL, atLevels = NULL, minChildCount = NULL, maxChildCount = NULL, emptyGroups = "exclude", outlineGroups = "exclude", outlineLinkedGroupExists = NULL, includeDescendantGroups = FALSE, rowNumbers = NULL, cells = 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.
includeDescendantGroups
Default 'FALSE'. Specify true to also return all descendants of data groups that match the specified criteria.
rowNumbers
An integer vector specifying row numbers that constrains the data groups to be found.
cells
A 'PivotCell' object or a list of 'PivotCell' objects to specify one or more cells that must intersect the data groups.
A list of data groups matching the specified criteria.
findColumnDataGroups()
Find column data groups that match specified criteria.
PivotTable$findColumnDataGroups( matchMode = "simple", variableNames = NULL, variableValues = NULL, totals = "include", calculationNames = NULL, atLevels = NULL, minChildCount = NULL, maxChildCount = NULL, emptyGroups = "exclude", includeDescendantGroups = FALSE, columnNumbers = NULL, cells = 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".
includeDescendantGroups
Default 'FALSE'. Specify true to also return all descendants of data groups that match the specified criteria.
columnNumbers
An integer vector specifying column numbers that constrains the data groups to be found.
cells
A 'PivotCell' object or a list of 'PivotCell' objects to specify one or more cells that must intersect the data groups.
A list of data groups matching the specified criteria.
getEmptyRows()
Retrieve row numbers for rows where all cells are empty.
PivotTable$getEmptyRows( NAasEmpty = TRUE, zeroAsEmpty = FALSE, zeroTolerance = 1e-06, includeOutlineRows = FALSE )
NAasEmpty
'TRUE' (default) specifies that 'NA' is treated as empty.
zeroAsEmpty
'TRUE' specifies that zero is treated as empty, default 'FALSE'.
zeroTolerance
The tolerance for zero comparisons, default 0.000001.
includeOutlineRows
'TRUE' to also examine outline rows, default 'FALSE'.
'NULL' cell values are always regarded as empty.
An integer vector of row numbers.
getEmptyColumns()
Retrieve column numbers for columns where all cells are empty.
PivotTable$getEmptyColumns( NAasEmpty = TRUE, zeroAsEmpty = FALSE, zeroTolerance = 1e-06 )
NAasEmpty
'TRUE' (default) specifies that 'NA' is treated as empty.
zeroAsEmpty
'TRUE' specifies that zero is treated as empty, default 'FALSE'.
zeroTolerance
The tolerance for zero comparisons, default 0.000001.
'NULL' cell values are always regarded as empty.
An integer vector of column numbers.
getCell()
Get the cell at the specified row and column coordinates in the pivot table.
PivotTable$getCell(r = NULL, c = NULL)
r
Row number of the cell to retrieve.
c
Column number of the cell to retrieve.
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.
A 'PivotCell' object representing the cell.
getCells()
Retrieve cells by a combination of row and/or column numbers. See the "Finding and Formatting" vignette for graphical examples.
PivotTable$getCells( specifyCellsAsList = TRUE, rowNumbers = NULL, columnNumbers = NULL, cellCoordinates = NULL, excludeEmptyCells = FALSE, groups = NULL, rowGroups = NULL, columnGroups = NULL, matchMode = "simple" )
specifyCellsAsList
Specify how cells are retrieved. Default 'TRUE'. More information is provided in the details section.
rowNumbers
A vector of row numbers that specify the rows or cells to retrieve.
columnNumbers
A vector of column numbers that specify the columns or cells to retrieve.
cellCoordinates
A list of two-element vectors that specify the coordinates of cells to retrieve. Ignored when 'specifyCellsAsList=FALSE'.
excludeEmptyCells
Default 'FALSE'. Specify 'TRUE' to exclude empty cells.
groups
A '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.
rowGroups
A '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.
columnGroups
A '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.
matchMode
Either "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.
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'.
A list of 'PivotCell' objects.
findCells()
Find cells matching specified criteria. See the "Finding and Formatting" vignette for graphical examples.
PivotTable$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 )
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.
minValue
A numerical value specifying a minimum value threshold.
maxValue
A numerical value specifying a maximum value threshold.
exactValues
A vector or list specifying a set of allowed values.
valueRanges
A 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. See details.
includeNull
specify TRUE to include 'NULL' in the matched cells, FALSE to exclude 'NULL' values.
includeNA
specify TRUE to include 'NA' in the matched cells, FALSE to exclude 'NA' values.
emptyCells
A word that specifies how empty cells are matched - must be one of "include" (default), "exclude" or "only".
outlineCells
A word that specifies how outline cells are matched - must be one of "include", "exclude" (default) or "only".
rowNumbers
A vector of row numbers that specify the rows or cells to constrain the search.
columnNumbers
A vector of column numbers that specify the columns or cells to constrain the search.
cellCoordinates
A list of two-element vectors that specify the coordinates of cells to constrain the search.
groups
A '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.
rowGroups
A '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.
columnGroups
A '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.
rowColumnMatchMode
Either "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.
cells
A 'PivotCell' object or a list of 'PivotCell' objects to constrain the scope of the search.
lowN
Find the first N cells (ascending order, lowest values first).
highN
Find the last N cells (descending order, highest values first).
The valueRanges parameter can be any of the following
forms:
(1) a specific value, e.g. 12.
(2) a specific value equality condition, e.g. "v==12", where v
represents the cell value.
(3) a value range expression using the following abbreviated form:
"value1<=v<value2", e.g. "10<=v<15". Only "<" or "<=" can be used
in these value range expressions.
(4) a standard R logical expression, e.g.
"10<=v && v<15".
Basic R functions that test the value can also be
used, e.g. is.na(v).
A list of 'PivotCell' objects.
findGroupColumnNumbers()
Find the column numbers associated with a specific data group or groups.
PivotTable$findGroupColumnNumbers(group = NULL, collapse = FALSE)
group
A 'PivotDataGroup' in the column data groups (i.e. a column heading) or a list of column data groups.
collapse
A logical value specifying whether the return value should be simplified. See 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.
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.
findGroupRowNumbers()
Find the row numbers associated with a specific data group or groups.
PivotTable$findGroupRowNumbers(group = NULL, collapse = FALSE)
group
A 'PivotDataGroup' in the row data groups (i.e. a row heading) or a list of row data groups.
collapse
A logical value specifying whether the return value should be simplified. See 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.
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.
removeColumn()
Remove a column from the pivot table.
PivotTable$removeColumn(c = NULL)
c
The column number. The first column is column 1, excluding the column(s) associated with row-headings.
This method removes both the related column group and cells.
No return value.
removeColumns()
Remove multiple column from the pivot table.
PivotTable$removeColumns(columnNumbers = NULL)
columnNumbers
The column numbers. The first column is column 1, excluding the column(s) associated with row-headings.
This method removes both the related column groups and cells.
No return value.
removeEmptyColumns()
Remove columns where all cells are empty.
PivotTable$removeEmptyColumns( NAasEmpty = TRUE, zeroAsEmpty = FALSE, zeroTolerance = 1e-06 )
NAasEmpty
'TRUE' (default) specifies that 'NA' is treated as empty.
zeroAsEmpty
'TRUE' specifies that zero is treated as empty, default 'FALSE'.
zeroTolerance
The tolerance for zero comparisons, default 0.000001.
'NULL' cell values are always regarded as empty.
No return value.
removeRow()
Remove a row from the pivot table.
PivotTable$removeRow(r = NULL)
r
The row number. The first row is row 1, excluding the row(s) associated with column-headings.
This method removes both the related row group and cells.
No return value.
removeRows()
Remove multiple rows from the pivot table.
PivotTable$removeRows(rowNumbers = NULL)
rowNumbers
The row numbers. The first row is row 1, excluding the rows(s) associated with column-headings.
This method removes both the related row groups and cells.
No return value.
removeEmptyRows()
Remove rows where all cells are empty.
PivotTable$removeEmptyRows( NAasEmpty = TRUE, zeroAsEmpty = FALSE, zeroTolerance = 1e-06, includeOutlineRows = FALSE )
NAasEmpty
'TRUE' (default) specifies that 'NA' is treated as empty.
zeroAsEmpty
'TRUE' specifies that zero is treated as empty, default 'FALSE'.
zeroTolerance
The tolerance for zero comparisons, default 0.000001.
includeOutlineRows
'TRUE' to also remove empty outline rows, default 'FALSE'.
'NULL' cell values are always regarded as empty.
No return value.
print()
Outputs a plain text representation of the pivot table to the console or returns a character representation of the pivot table.
PivotTable$print(asCharacter = FALSE, showRowGroupHeaders = FALSE)
asCharacter
'FALSE'(default) outputs to the console, specify 'TRUE' to instead return a character value (does not output to console).
showRowGroupHeaders
'TRUE' to include the row group headers in the output, default 'FALSE'.
Plain text representation of the pivot table.
asMatrix()
Convert the pivot table to a matrix, where the data group headings are included in the body of the matrix. This method tends to produce a character matrix.
PivotTable$asMatrix( includeHeaders = TRUE, repeatHeaders = FALSE, rawValue = FALSE, showRowGroupHeaders = FALSE )
includeHeaders
'TRUE' (default) to include the headings in the body of the matrix. Specifying 'FALSE' omits the headings.
repeatHeaders
'FALSE' (default) only outputs the first occurrence of each header. Specify 'TRUE' to repeat the headings.
rawValue
'FALSE' (default) outputs the formatted (character) values. Specify 'TRUE' to output the raw cell values.
showRowGroupHeaders
'TRUE' to include the row group headers in the matrix, default 'FALSE'.
The newer 'asDataMatrix()' tends to produce more a useful matrix. See the "Outputs" vignette for a comparison of outputs.
A matrix.
asDataMatrix()
Convert the pivot table to a matrix, where the data group headings are included as row/column headings in the matrix. This method tends to produce a numeric matrix.
PivotTable$asDataMatrix( includeHeaders = TRUE, rawValue = TRUE, separator = " " )
includeHeaders
'TRUE' (default) to include the headings in the matrix. Specifying 'FALSE' omits the headings.
rawValue
'TRUE' (default) outputs the raw cell values. Specify 'FALSE' to output the formatted (character) values.
separator
Specifies the character value used to concatenate data group captions where multiple levels exist in the data group hierarchy.
Where there are multiple levels in a data group hierarchy, the captions are concatenated to form the row/column headings in the matrix. See the "Outputs" vignette for a comparison of outputs.
A matrix.
asDataFrame()
Convert the pivot table to a data frame, combining multiple levels of headings with the specified separator and/or exporting the row groups as columns in the data frame.
PivotTable$asDataFrame( separator = " ", stringsAsFactors = NULL, forceNumeric = FALSE, rowGroupsAsColumns = FALSE )
separator
Specifies the character value used to concatenate data group captions where multiple levels exist in the data group hierarchy.
stringsAsFactors
Specify 'TRUE' to convert strings to factors, default is 'default.stringsAsFactors()' for R < 4.1.0 and 'FALSE' for R >= 4.1.0.
forceNumeric
Specify 'TRUE' to force the conversion of cell values to a numeric value, default 'FALSE'.
rowGroupsAsColumns
Specify 'TRUE' to include the row groups as additional columns in the data frame. Default 'FALSE'.
See the "Outputs" vignette for more details and examples
A data frame.
asTidyDataFrame()
Convert the pivot table to tidy data frame, where each cell in the body of the pivot table becomes one row in the data frame.
PivotTable$asTidyDataFrame( includeGroupCaptions = TRUE, includeGroupValues = TRUE, separator = " ", stringsAsFactors = NULL, excludeEmptyCells = TRUE )
includeGroupCaptions
'TRUE' (default) to include the data group captions as columns in the data frame.
includeGroupValues
'TRUE' (default) to include the data group values as columns in the data frame.
separator
Specifies the character value used to concatenate filter values where multiple values exist in a filter.
stringsAsFactors
Specify 'TRUE' to convert strings to factors, default is 'default.stringsAsFactors()' for R < 4.1.0 and 'FALSE' for R >= 4.1.0.
excludeEmptyCells
Specify 'FALSE' to also include rows for empty cells in the data frame, default 'TRUE'.
See the "Outputs" vignette for more details and examples
A data frame.
getMerges()
Generate a list of the merged cell information arising from the data group hierarchies. This is an internal method used to support rendering the pivot table.
PivotTable$getMerges(axis = NULL)
axis
Either "row" or "column".
A list containing details of the merged cells.
asBasicTable()
Convert the pivot table to a 'basictabler' table (from the 'basictabler' R package) which allows further custom manipulation of the pivot table.
PivotTable$asBasicTable( exportOptions = NULL, compatibility = NULL, showRowGroupHeaders = FALSE )
exportOptions
A list of additional export options - see the "A1. Appendix" for details.
compatibility
A list containing compatibility options to force legacy behaviours in the resulting 'basictabler' table.
showRowGroupHeaders
'TRUE' to include the row group headers in the matrix, default 'FALSE'.
See the "Outputs" vignette for more details and examples
A 'basictabler' table.
getCss()
Get the CSS declarations for the pivot table.
PivotTable$getCss(styleNamePrefix = NULL)
styleNamePrefix
A character variable specifying a prefix for all named CSS styles, to avoid style name collisions where multiple pivot tables exist.
See the "Outputs" vignette for more details and examples.
A character value containing the CSS style declaration.
getHtml()
Generate a HTML representation of the pivot table, optionally including additional detail for debugging purposes.
PivotTable$getHtml( styleNamePrefix = NULL, includeHeaderValues = FALSE, includeRCFilters = FALSE, includeCalculationFilters = FALSE, includeWorkingData = FALSE, includeEvaluationFilters = FALSE, includeCalculationNames = FALSE, includeRawValue = FALSE, includeTotalInfo = FALSE, exportOptions = NULL, showRowGroupHeaders = FALSE )
styleNamePrefix
A character variable specifying a prefix for all named CSS styles, to avoid style name collisions where multiple pivot tables exist.
includeHeaderValues
Default 'FALSE', specify 'TRUE' to render this debug information.
includeRCFilters
Default 'FALSE', specify 'TRUE' to render this debug information.
includeCalculationFilters
Default 'FALSE', specify 'TRUE' to render this debug information.
includeWorkingData
Default 'FALSE', specify 'TRUE' to render this debug information.
includeEvaluationFilters
Default 'FALSE', specify 'TRUE' to render this debug information.
includeCalculationNames
Default 'FALSE', specify 'TRUE' to render this debug information.
includeRawValue
Default 'FALSE', specify 'TRUE' to render this debug information.
includeTotalInfo
Default 'FALSE', specify 'TRUE' to render this debug information.
exportOptions
A list of additional export options - see the "A1. Appendix" for details.
showRowGroupHeaders
Default 'FALSE', specify 'TRUE' to render the row group headings. See the "Data Groups" vignette for details.
See the "Outputs" vignette for more details and examples.
A list containing HTML tags from the 'htmltools' package. Convert this to a character variable using 'as.character()'.
saveHtml()
Save a HTML representation of the pivot table to file, optionally including additional detail for debugging purposes.
PivotTable$saveHtml( filePath = NULL, fullPageHTML = TRUE, styleNamePrefix = NULL, includeHeaderValues = FALSE, includeRCFilters = FALSE, includeCalculationFilters = FALSE, includeWorkingData = FALSE, includeEvaluationFilters = FALSE, includeCalculationNames = FALSE, includeRawValue = FALSE, includeTotalInfo = FALSE, exportOptions = NULL, showRowGroupHeaders = FALSE )
filePath
The file to save the HTML to.
fullPageHTML
'TRUE' (default) includes basic HTML around the pivot table HTML so that the result file is a valid HTML file.
styleNamePrefix
A character variable specifying a prefix for all named CSS styles, to avoid style name collisions where multiple pivot tables exist.
includeHeaderValues
Default 'FALSE', specify 'TRUE' to render this debug information.
includeRCFilters
Default 'FALSE', specify 'TRUE' to render this debug information.
includeCalculationFilters
Default 'FALSE', specify 'TRUE' to render this debug information.
includeWorkingData
Default 'FALSE', specify 'TRUE' to render this debug information.
includeEvaluationFilters
Default 'FALSE', specify 'TRUE' to render this debug information.
includeCalculationNames
Default 'FALSE', specify 'TRUE' to render this debug information.
includeRawValue
Default 'FALSE', specify 'TRUE' to render this debug information.
includeTotalInfo
Default 'FALSE', specify 'TRUE' to render this debug information.
exportOptions
A list of additional export options - see the "A1. Appendix" for details.
showRowGroupHeaders
Default 'FALSE', specify 'TRUE' to render the row group headings. See the "Data Groups" vignette for details.
See the "Outputs" vignette for more details and examples.
No return value.
renderPivot()
Render a HTML representation of the pivot table as an HTML widget, optionally including additional detail for debugging purposes.
PivotTable$renderPivot( width = NULL, height = NULL, styleNamePrefix = NULL, includeHeaderValues = FALSE, includeRCFilters = FALSE, includeCalculationFilters = FALSE, includeWorkingData = FALSE, includeEvaluationFilters = FALSE, includeCalculationNames = FALSE, includeRawValue = FALSE, includeTotalInfo = FALSE, exportOptions = NULL, showRowGroupHeaders = FALSE )
width
The width of the widget.
height
The height of the widget.
styleNamePrefix
A character variable specifying a prefix for all named CSS styles, to avoid style name collisions where multiple pivot tables exist.
includeHeaderValues
Default 'FALSE', specify 'TRUE' to render this debug information.
includeRCFilters
Default 'FALSE', specify 'TRUE' to render this debug information.
includeCalculationFilters
Default 'FALSE', specify 'TRUE' to render this debug information.
includeWorkingData
Default 'FALSE', specify 'TRUE' to render this debug information.
includeEvaluationFilters
Default 'FALSE', specify 'TRUE' to render this debug information.
includeCalculationNames
Default 'FALSE', specify 'TRUE' to render this debug information.
includeRawValue
Default 'FALSE', specify 'TRUE' to render this debug information.
includeTotalInfo
Default 'FALSE', specify 'TRUE' to render this debug information.
exportOptions
A list of additional export options - see the "A1. Appendix" for details.
showRowGroupHeaders
Default 'FALSE', specify 'TRUE' to render the row group headings. See the "Data Groups" vignette for details.
See the "Outputs" vignette for more details and examples.
A HTML widget from the 'htmlwidgets' package.
getLatex()
Generate a Latex representation of the pivot table.
PivotTable$getLatex( caption = NULL, label = NULL, fromRow = NULL, toRow = NULL, fromColumn = NULL, toColumn = NULL, boldHeadings = FALSE, italicHeadings = FALSE, exportOptions = NULL )
caption
The caption to appear above the table.
label
The label to use when referring to the table elsewhere in the document
fromRow
The row number to render from.
toRow
The row number to render to.
fromColumn
The column number to render from.
toColumn
The column number to render to.
boldHeadings
Default 'FALSE', specify 'TRUE' to render headings in bold.
italicHeadings
Default 'FALSE', specify 'TRUE' to render headings in italic.
exportOptions
A list of additional export options - see the "A1. Appendix" for details.
A character variable containing the Latex representation of the pivot table.
writeToExcelWorksheet()
Write the pivot table into the specified workbook and worksheet at the specified row-column location.
PivotTable$writeToExcelWorksheet( wb = NULL, wsName = NULL, topRowNumber = NULL, leftMostColumnNumber = NULL, outputHeadingsAs = "formattedValueAsText", outputValuesAs = "rawValue", applyStyles = TRUE, mapStylesFromCSS = TRUE, exportOptions = NULL, showRowGroupHeaders = FALSE )
wb
A 'Workbook' object representing the Excel file being written to.
wsName
A character value specifying the name of the worksheet to write to.
topRowNumber
An integer value specifying the row number in the Excel worksheet to write the pivot table.
leftMostColumnNumber
An integer value specifying the column number in the Excel worksheet to write the pivot table.
outputHeadingsAs
Must be one of "rawValue", "formattedValueAsText" (default) or "formattedValueAsNumber" to specify how data groups are written into the Excel sheet.
outputValuesAs
Must be one of "rawValue" (default), "formattedValueAsText" or "formattedValueAsNumber" to specify how cell values are written into the Excel sheet.
applyStyles
Default 'TRUE' to write styling information to the cell.
mapStylesFromCSS
Default 'TRUE' to automatically convert CSS style declarations to their Excel equivalents.
exportOptions
A list of additional export options - see the "A1. Appendix" for details.
showRowGroupHeaders
Default 'FALSE', specify 'TRUE' to write row group headers.
No return value.
trace()
Capture a call for tracing purposes. This is an internal method.
PivotTable$trace(methodName, desc, detailList = NULL)
methodName
The name of the method being invoked.
desc
Short description of method call.
detailList
A list containing detail such as parameter values.
No return value.
showBatchInfo()
Output batch information to the console.
PivotTable$showBatchInfo()
No return value.
asList()
Return the contents of the pivot table as a list for debugging.
PivotTable$asList()
A list of various object properties.
asJSON()
Return the contents of the pivot table as JSON for debugging.
PivotTable$asJSON()
A JSON representation of various object properties.
viewJSON()
Use the 'listviewer' package to view the pivot table as JSON for debugging.
PivotTable$viewJSON()
No return value.
finalize()
Clean-up the pivot table.
PivotTable$finalize()
No return value.
clone()
The objects of this class are cloneable with this method.
PivotTable$clone(deep = FALSE)
deep
Whether to make a deep clone.
# The package vignettes include extensive examples of working with the # PivotTable class. library(pivottabler) pt <- PivotTable$new() pt$addData(bhmtrains) pt$addColumnDataGroups("TrainCategory") pt$addRowDataGroups("TOC") pt$defineCalculation(calculationName="TotalTrains", summariseExpression="n()") pt$renderPivot()
# The package vignettes include extensive examples of working with the # PivotTable class. library(pivottabler) pt <- PivotTable$new() pt$addData(bhmtrains) pt$addColumnDataGroups("TrainCategory") pt$addRowDataGroups("TOC") pt$defineCalculation(calculationName="TotalTrains", summariseExpression="n()") pt$renderPivot()
The pivottabler
function is primarily intended for use with Shiny web
applications.
pivottabler( pt, width = NULL, height = NULL, styleNamePrefix = NULL, includeRCFilters = FALSE, includeCalculationFilters = FALSE, includeWorkingData = FALSE, includeEvaluationFilters = FALSE, includeCalculationNames = FALSE, includeRawValue = FALSE )
pivottabler( pt, width = NULL, height = NULL, styleNamePrefix = NULL, includeRCFilters = FALSE, includeCalculationFilters = FALSE, includeWorkingData = FALSE, includeEvaluationFilters = FALSE, includeCalculationNames = FALSE, includeRawValue = FALSE )
pt |
The pivot table to render. |
width |
The target width. |
height |
The target height. |
styleNamePrefix |
A text prefix to be prepended to the CSS declarations (to ensure uniqueness). |
includeRCFilters |
Show/hide filter detail for debugging. |
includeCalculationFilters |
Show/hide filter detail for debugging. |
includeWorkingData |
Show/hide working data detail for debugging. |
includeEvaluationFilters |
Show/hide filter detail for debugging. |
includeCalculationNames |
Show/hide filter detail for debugging. |
includeRawValue |
Show/hide filter detail for debugging. |
A HTML widget.
# See the Shiny vignette in this package for examples.
# See the Shiny vignette in this package for examples.
Standard function for Shiny scaffolding.
pivottablerOutput(outputId, width = "100%", height = "100%")
pivottablerOutput(outputId, width = "100%", height = "100%")
outputId |
The id of the html element that will contain the htmlwidget. |
width |
The target width of the htmlwidget. |
height |
The target height of the htmlwidget. |
processIdentifier
is a utility function that wraps an illegal
identifier in backticks.
processIdentifier(identifier)
processIdentifier(identifier)
identifier |
The identifier that may be illegal. |
The identifier wrapped in backticks (if illegal) or unchanged.
processIdentifiers
is a utility function that wraps illegal
identifiers in backticks.
processIdentifiers(identifiers)
processIdentifiers(identifiers)
identifiers |
The identifiers that may be illegal. |
The identifiers wrapped in backticks (if illegal) or unchanged.
A reference dataset containing the full results of an example performance comparison for different pivot table test cases.
pvtperfresults
pvtperfresults
A data frame with 216 rows and 11 variables:
A unique identifier for this test case.
The pivot table evaluation mode used for this test case.
The number of rows in the data frame used for this test case.
The number of cells in the pivot table used for this test case.
The pivot table argument check mode used this test case.
The pivot table processing library used this test case.
A description of this test case.
A logical value indicating whether this test case completed.
The user time for this test case.
The system time for this test case.
The elapsed time for this test case.
A reference dataset containing summary results of an example performance comparison for different pivot table test cases.
pvtperfsummary
pvtperfsummary
A data frame with 36 rows and 18 variables:
A unique identifier for this test case.
The pivot table evaluation mode used for this test case.
The number of rows in the data frame used for this test case.
The number of cells in the pivot table used for this test case.
The pivot table argument check mode used this test case.
The pivot table processing library used this test case.
A description of this test case.
The average user time for this test case.
The average system time for this test case.
The average elapsed time for this test case.
The minimum user time for this test case.
The maximum user time for this test case.
The minimum system time for this test case.
The maximum system time for this test case.
The minimum elapsed time for this test case.
The maximum elapsed time for this test case.
A short name for this test case.
An index for this test case.
The qhpvt
function renders a basic pivot table as a HTML widget with
one line of R.
qhpvt( dataFrame, rows = NULL, columns = NULL, calculations = NULL, theme = NULL, replaceExistingStyles = FALSE, tableStyle = NULL, headingStyle = NULL, cellStyle = NULL, totalStyle = NULL, ... )
qhpvt( dataFrame, rows = NULL, columns = NULL, calculations = NULL, theme = NULL, replaceExistingStyles = FALSE, tableStyle = NULL, headingStyle = NULL, cellStyle = NULL, totalStyle = NULL, ... )
dataFrame |
The data frame containing the data to be summarised in the pivot table. |
rows |
A character vector of variable names to be plotted on the rows of the pivot table, or "=" to specify the position of the calculations. |
columns |
A character vector of variable names to be plotted on the columns of the pivot table, or "=" to specify the position of the calculations. |
calculations |
One or more summary calculations to use to calculate the values of the cells in the pivot table. |
theme |
Either the name of a built-in theme (default, largeplain, compact or blank/none) or a list which specifies the default formatting for the table. |
replaceExistingStyles |
TRUE to completely replace the default styling with the specified tableStyle, headingStyle, cellStyle and/or totalStyle |
tableStyle |
A list of CSS style declarations that apply to the table. |
headingStyle |
A list of CSS style declarations that apply to the heading cells in the table. |
cellStyle |
A list of CSS style declarations that apply to the normal cells in the table. |
totalStyle |
A list of CSS style declarations that apply to the total cells in the table. |
... |
Additional arguments, currently format, formats, totals, styleNamePrefix, compatibility and/or argumentCheckMode. |
A HTML widget.
qhpvt(bhmtrains, "TOC", "TrainCategory", "n()") qhpvt(bhmtrains, "TOC", "TrainCategory", c("Mean Speed"="mean(SchedSpeedMPH, na.rm=TRUE)", "Std Dev Speed"="sd(SchedSpeedMPH, na.rm=TRUE)"), formats=list("%.0f", "%.1f"), totals=list("TOC"="All TOCs", "TrainCategory"="All Categories"))
qhpvt(bhmtrains, "TOC", "TrainCategory", "n()") qhpvt(bhmtrains, "TOC", "TrainCategory", c("Mean Speed"="mean(SchedSpeedMPH, na.rm=TRUE)", "Std Dev Speed"="sd(SchedSpeedMPH, na.rm=TRUE)"), formats=list("%.0f", "%.1f"), totals=list("TOC"="All TOCs", "TrainCategory"="All Categories"))
The qlpvt
function returns the Latex for a basic pivot table with
one line of R.
qlpvt(dataFrame, rows = NULL, columns = NULL, calculations = NULL, ...)
qlpvt(dataFrame, rows = NULL, columns = NULL, calculations = NULL, ...)
dataFrame |
The data frame containing the data to be summarised in the pivot table. |
rows |
A character vector of variable names to be plotted on the rows of the pivot table, or "=" to specify the position of the calculations. |
columns |
A character vector of variable names to be plotted on the columns of the pivot table, or "=" to specify the position of the calculations. |
calculations |
One or more summary calculations to use to calculate the values of the cells in the pivot table. |
... |
Additional arguments, currently format, formats, totals, argumentCheckMode, compatibility, caption and/or label. See the Latex output vignette for a description of caption and label. |
Latex.
qlpvt(bhmtrains, "TOC", "TrainCategory", "n()") qlpvt(bhmtrains, "TOC", "TrainCategory", "n()", caption="my caption", label="mylabel")
qlpvt(bhmtrains, "TOC", "TrainCategory", "n()") qlpvt(bhmtrains, "TOC", "TrainCategory", "n()", caption="my caption", label="mylabel")
The qpvt
function builds a basic pivot table with one line of R.
qpvt( dataFrame, rows = NULL, columns = NULL, calculations = NULL, theme = NULL, replaceExistingStyles = FALSE, tableStyle = NULL, headingStyle = NULL, cellStyle = NULL, totalStyle = NULL, ... )
qpvt( dataFrame, rows = NULL, columns = NULL, calculations = NULL, theme = NULL, replaceExistingStyles = FALSE, tableStyle = NULL, headingStyle = NULL, cellStyle = NULL, totalStyle = NULL, ... )
dataFrame |
The data frame containing the data to be summarised in the pivot table. |
rows |
A character vector of variable names to be plotted on the rows of the pivot table, or "=" to specify the position of the calculations. |
columns |
A character vector of variable names to be plotted on the columns of the pivot table, or "=" to specify the position of the calculations. |
calculations |
One or more summary calculations to use to calculate the values of the cells in the pivot table. |
theme |
Either the name of a built-in theme (default, largeplain, compact or blank/none) or a list which specifies the default formatting for the table. |
replaceExistingStyles |
TRUE to completely replace the default styling with the specified tableStyle, headingStyle, cellStyle and/or totalStyle |
tableStyle |
A list of CSS style declarations that apply to the table. |
headingStyle |
A list of CSS style declarations that apply to the heading cells in the table. |
cellStyle |
A list of CSS style declarations that apply to the normal cells in the table. |
totalStyle |
A list of CSS style declarations that apply to the total cells in the table. |
... |
Additional arguments, currently format, formats, totals, compatibility and/or argumentCheckMode. |
A pivot table.
qpvt(bhmtrains, "TOC", "TrainCategory", "n()") qpvt(bhmtrains, c("=", "TOC"), c("TrainCategory", "PowerType"), c("Number of Trains"="n()", "Maximum Speed"="max(SchedSpeedMPH, na.rm=TRUE)"))
qpvt(bhmtrains, "TOC", "TrainCategory", "n()") qpvt(bhmtrains, c("=", "TOC"), c("TrainCategory", "PowerType"), c("Number of Trains"="n()", "Maximum Speed"="max(SchedSpeedMPH, na.rm=TRUE)"))
renderBasicTable
is utility function that renders a basic table into a
package vignette. This function is primarily intended for internal use by
the pivottabler package.
renderBasicTable( matrix = NULL, stylePrefix = NULL, columnNamesAsHeader = FALSE, rowNamesAsHeader = FALSE, columnAlignment = "right" )
renderBasicTable( matrix = NULL, stylePrefix = NULL, columnNamesAsHeader = FALSE, rowNamesAsHeader = FALSE, columnAlignment = "right" )
matrix |
Tabular data to render. |
stylePrefix |
Text prefix for CSS style declarations. |
columnNamesAsHeader |
Include column names in output (if FALSE, the first row from the matrix is used as the column headings). |
rowNamesAsHeader |
Include row names in output. |
columnAlignment |
A character vector specifying the horizontal alignment of each column. |
A basic table rendered as a HTML widget.
renderBasicTable(matrix(c(1:12), nrow=3))
renderBasicTable(matrix(c(1:12), nrow=3))
Standard function for Shiny scaffolding.
renderPivottabler(expr, env = parent.frame(), quoted = FALSE)
renderPivottabler(expr, env = parent.frame(), quoted = FALSE)
expr |
The R expression to execute and render in the Shiny web application. |
env |
Standard shiny argument for a render function. |
quoted |
Standard shiny argument for a render function. |
skipExportingValue
is a utility function that returns true if
the current value should be skipped when exporting.
skipExportingValue(rawValue, exportOptions)
skipExportingValue(rawValue, exportOptions)
rawValue |
The value to check. |
exportOptions |
A list of options controlling export behaviour. |
TRUE or FALSE indicating whether the current value should be skipped.
A reference dataset listing the codes, names and locations of trains stations in Great Britain.
trainstations
trainstations
A data frame with 2568 rows and 7 variables:
3-letter code for the station
The name of the station
The UK Ordnance Survey Easting coordinate for the station
The UK Ordnance Survey Northing coordinate for the station
Grid reference for the station
Latitude of the station location
Longitude of the station location
https://www.recenttraintimes.co.uk/
typeSafeIntersect
preserves data types in a way that the
base::intersect
function does not, e.g. for Date values.
typeSafeIntersect(x, y, dedupe = FALSE)
typeSafeIntersect(x, y, dedupe = FALSE)
x |
First set of values. |
y |
Second set of values. |
dedupe |
Specify TRUE to remove duplicate values. |
A vector containing the intersection of x and y.
typeSafeUnion
preserves data types in a way that the
base::union
function does not, e.g. for Date values.
typeSafeUnion(x, y, dedupe = FALSE)
typeSafeUnion(x, y, dedupe = FALSE)
x |
First set of values. |
y |
Second set of values. |
dedupe |
Specify TRUE to remove duplicate values. |
A vector containing the union of x and y
typeSafeUnlist
tries to preserve data types in a way that the
base::unlist
function does not for Date, POSIXct and POSIXlt values.
typeSafeUnlist(x)
typeSafeUnlist(x)
x |
A list to convert to a vector. |
If a list containing mixed types is specified, then typeSafeUnlist
falls back to using base::unlist
.
A vector containing the values from x.
vreConvertSimpleNumericRange
is a utility function that converts
a simple range expression of the form "value1<=v<value2" to a standard
R logical expression of the form "value1<=v && v<value2".
vreConvertSimpleNumericRange(vre)
vreConvertSimpleNumericRange(vre)
vre |
The value range expression to examine. |
A standard R logical expression.
vreGetSingleValue
is a utility function reads the single value
from a value range expression (it assumes the specified
is either numeric, a number expressed as
text or an expression of the form "v=" or "v==").
vreGetSingleValue(vre)
vreGetSingleValue(vre)
vre |
The value range expression to examine. |
The value read from the expression.
vreHexToClr
converts a colour in hex format
(#RRGGBB) into a list of three element (r, g and b).
vreHexToClr(hexclr)
vreHexToClr(hexclr)
hexclr |
The colour to convert. |
The converted colour.
vreIsEqual
tests whether two values are equal
within sqrt(.Machine$double.eps).
vreIsEqual(value1, value2)
vreIsEqual(value1, value2)
value1 |
The first value to compare. |
value2 |
The second value to compare. |
'TRUE' if the two numbers are equal, 'FALSE' otherwise.
vreIsMatch
tests a value (e.g. from a cell) matches
the criteria specified in a value range expression.
vreIsMatch(vre, v, testOnly = FALSE)
vreIsMatch(vre, v, testOnly = FALSE)
vre |
The value range expression. |
v |
The value. |
testOnly |
'TRUE' if this comparison is just a test. |
'TRUE' if v matches the criteria specified in the value range expression, 'FALSE' otherwise.
vreIsSingleValue
is a utility function that returns 'TRUE' if the
specified value range expression is a simple range expression of the
form "value1<=v<value2", where the logical comparisons can be < or <= only
and the values must be numbers.
vreIsSimpleNumericRange(vre)
vreIsSimpleNumericRange(vre)
vre |
The value range expression to examine. |
'TRUE' if vre is a simple range expression, 'FALSE' otherwise.
vreIsSingleValue
is a utility function that returns 'TRUE' if the
specified value range expression is either numeric, a number expressed as
text or an expression of the form "v=" or "v==".
vreIsSingleValue(vre)
vreIsSingleValue(vre)
vre |
The value range expression to examine. |
'TRUE' if vre is a single value, 'FALSE' otherwise.
vreScale2Colours
takes a value from a range and
scales it proportionally into a colour from a colour gradient.
vreScale2Colours(clr1, clr2, vMin, vMax, value)
vreScale2Colours(clr1, clr2, vMin, vMax, value)
clr1 |
The colour representing the lower value of the target range. |
clr2 |
The colour representing the upper value of the target range. |
vMin |
The lower value of the source range. |
vMax |
The upper value of the source range. |
value |
The source value to rescale into the target range. |
The value scaled into the target colour gradient.
vreScaleNumber
takes a value from one range and
scales it proportionally into another range.
vreScaleNumber(n1, n2, vMin, vMax, value, decimalPlaces = 3)
vreScaleNumber(n1, n2, vMin, vMax, value, decimalPlaces = 3)
n1 |
The lower value of the target range. |
n2 |
The upper value of the target range. |
vMin |
The lower value of the source range. |
vMax |
The upper value of the source range. |
value |
The source value to rescale into the target range. |
decimalPlaces |
The number of decimal places to round the result to. |
The value rescaled into the target range.