The PivotTable class represents a pivot table and is the primary class for constructing and interacting with the pivot table.
PivotTable
Object of R6Class
with properties and methods that
define a pivot table.
R6Class
object.
argumentCheckMode
A number (0-4 meaning none, minimal, basic, balanced, full) indicating the argument checking level.
traceEnabled
A logical value indicating whether actions are logged to a trace file.
processingLibrary
A character value indicating the processing library being used (base, dplyr, data.table).
data
A PivotData object containing the data frames used to populate the pivot table.
rowGroup
The top PivotDataGroup in the parent-child hierarchy of row data groups.
columnGroup
The top PivotDataGroup in the parent-child hierarchy of column data groups.
calculationGroups
A PivotCalculationGroups object containing all of the pivot calculations in the pivot table.
calculationsPosition
"row" or "column" indicating where the calculation names will appear (only if multiple calculations are defined and visible in the pivot table).
evaluationMode
Either "sequential" or "batch" to specify how summary calculations (i.e. where type="summary") are evaluated.
batchInfo
Get a text summary of the batch calculations from the last evaluation of this pivot table.
cells
A PivotCells object containing all of the cells in the body of the pivot table.
rowCount
The number of rows in the table.
columnCount
The number of columns in the table.
theme
The name of the theme currently applied to the pivot table.
styles
A PivotStyles object containing the styles used to theme the pivot table.
allowExternalStyles
Enable support for external styles, when producing content for external systems.
allTimings
The time taken for various activities related to constructing the pivot table.
significantTimings
The time taken for various activities related to constructing the pivot table, where the elapsed time > 0.1 seconds.
For more complete explanations and examples please see the extensive vignettes supplied with this package.
new(processingLibrary="auto", traceEnabled=FALSE,
traceFile=NULL, argumentCheckMode="auto")
Create a new pivot table, including optionally enabling debug logging.
addData(df, dataName)
Add a data frame with the specified name to the pivot table.
getTopColumnGroups()
Get the very top column PivotDataGroup that sits at the top of the parent-child hierarchy.
getLeafColumnGroups()
Get the PivotDataGroups at the bottom of the column heading parent-child hierarchy.
addColumnDataGroups(variableName, atLevel, fromData=TRUE,
dataName, dataSortOrder="asc", dataFormat, onlyCombinationsThatExist=TRUE,
explicitListOfValues, calculationGroupName, expandExistingTotals=FALSE,
addTotal=TRUE, visualTotals=FALSE, totalPosition="after",
totalCaption="Total", preGroupData=TRUE)
Generate new column heading data groups based on the distinct values in a data frame or using explicitly specified data values.
normaliseColumnGroups()
Normalise the column heading data group hierachy so that all branches have the same number of levels - accomplished by adding empty child data groups where needed.
sortColumnDataGroups(levelNumber=1, orderBy="calculation",
sortOrder="desc", calculationGroupName="default", calculationName)
Sort the column heading data groups either by the data group data value, caption or based on calculation result values.
getTopRowGroups()
Get the left-most row PivotDataGroup that sits at the top of the parent-child hierarchy.
getLeafRowGroups()
Get the PivotDataGroups at the bottom of the row heading parent-child hierarchy.
addRowDataGroups(variableName, atLevel, fromData=TRUE,
dataName, dataSortOrder="asc", dataFormat, onlyCombinationsThatExist=TRUE,
explicitListOfValues, calculationGroupName, expandExistingTotals=FALSE,
addTotal=TRUE, visualTotals=FALSE, totalPosition="after",
totalCaption="Total", preGroupData=TRUE)
Generate new row heading data groups based on the distinct values in a data frame or using explicitly specified data values.
normaliseRowGroups()
Normalise the row heading data group hierachy so that all branches have the same number of levels - accomplished by adding empty child data groups where needed.
sortRowDataGroups(levelNumber=1, orderBy="calculation",
sortOrder="desc", calculationGroupName="default", calculationName)
Sort the row heading data groups either by the data group data value, caption or based on calculation result values.
addCalculationGroup(calculationGroupName)
Create a new calculation group (rarely needed since the default group is sufficient for almost all scenarios).
defineCalculation(calculationGroupName="default",
calculationName, caption, visible=TRUE, displayOrder, filters, format,
dataName, type="summary", valueName, summariseExpression,
calculationExpression, calculationFunction, basedOn, noDataValue,
noDataCaption)
Define a new calculation. See the PivotCalculation class for details.
addColumnCalculationGroups(calculationGroupName="default",
atLevel)
Add calculation names on columns (if more than one calculation is defined and visible, then the calculation names will appear as column headings).
addRowCalculationGroups(calculationGroupName="default",
atLevel)
Add calculation names on rows (if more than one calculation is defined and visible, then the calculation names will appear as row headings).
addStyle(styleName, declarations)
Define a new PivotStyle and add it to the PivotStyles collection.
createInlineStyle(baseStyleName, declarations)
Create a PivotStyle object that can be used to style individual cell in the pivot table.
generateCellStructure()
Generate the empty pivot table cells (after the row/column headings have been defined).
resetCells()
Clear the cells of the pivot table (should be done automatically after structural changes have been made to the pivot table).
evaluateCells()
Calculate the values of the cells in the body of the pivot table.
evaluatePivot()
A wrapper for calling normaliseColumnGroups(), normaliseRowGroups(), generateCellStructure() and evaluateCells() in sequence.
findRowDataGroups(matchMode="simple", variableNames=NULL,
variableValues=NULL, totals="include", calculationNames=NULL,
includeDescendantGroups=FALSE)
Find row data groups matching the specified criteria.
findColumnDataGroups(matchMode="simple", variableNames=NULL,
variableValues=NULL, totals="include", calculationNames=NULL,
includeDescendantGroups=FALSE)
Find column data groups matching the specified criteria.
getCells(specifyCellsAsList=FALSE, rowNumbers=NULL,
columnNumbers=NULL, cellCoordinates=NULL)
Retrieve cells by a combination of row and/or column numbers.
findCells(variableNames=NULL, variableValues=NULL,
totals="include", calculationNames=NULL, minValue=NULL, maxValue=NULL,
exactValues=NULL, includeNull=TRUE, includeNA=TRUE)
Find cells in the body of the pivot table matching the specified criteria.
print(asCharacter=FALSE)
Either print the pivot table to the console or retrieve it as a character value.
asMatrix(includeHeaders=TRUE, repeatHeaders=FALSE,
rawValue=FALSE)
Gets the pivot table as a matrix, with or without headings.
asDataFrame(separator=" ")
Gets the pivot table as a data frame, combining multiple levels of headings with the specified separator.
asTidyDataFrame(includeGroupCaptions=TRUE,
includeGroupValues=TRUE, separator=" ")
Gets the pivot table as a tidy data frame, where each cell in the body of the pivot table becomes one row in the data frame.
getCss(styleNamePrefix)
Get the CSS declarations for the entire pivot table.
getHtml(styleNamePrefix, includeHeaderValues=FALSE,
includeRCFilters=FALSE, includeCalculationFilters=FALSE,
includeWorkingData=FALSE, includeEvaluationFilters=FALSE,
includeCalculationNames=FALSE, includeRawValue=FALSE,
includeTotalInfo=FALSE)
Get the HTML representation of the pivot table, specifying the CSS style name prefix to use and whether additional debug information should be included in the pivot table.
saveHtml(filePath, fullPageHTML=TRUE, styleNamePrefix,
includeHeaderValues=FALSE, includeRCFilters=FALSE,
includeCalculationFilters=FALSE, includeWorkingData=FALSE,
includeEvaluationFilters=FALSE, includeCalculationNames=FALSE,
includeRawValue=FALSE, includeTotalInfo=FALSE)
Save the HTML representation of the pivot table to a file.
renderPivot(width, height, styleNamePrefix,
includeHeaderValues=FALSE, includeRCFilters=FALSE,
includeCalculationFilters=FALSE, includeWorkingData=FALSE,
includeEvaluationFilters=FALSE, includeCalculationNames=FALSE,
includeRawValue=FALSE, includeTotalInfo=FALSE)
Render the pivot table as a htmlwidget.
getLatex(caption=NULL, label=NULL, fromRow=NULL, toRow=NULL,
fromColumn=NULL, toColumn=NULL, boldHeadings=FALSE,
italicHeadings=FALSE)
Get the Latex representation of the pivot table, specifying the caption to appear above the table, the label to use when referring to the table elsewhere in the document and how headings should be styled.
writeToExcelWorksheet(wb=NULL, wsName=NULL, topRowNumber=NULL,
leftMostColumnNumber=NULL, mapStylesFromCSS=TRUE)
Output the pivot table into the specified workbook and worksheet at the specified row-column location.
showBatchInfo()
Show a text summary of the batch calculations from the last evaluation of this pivot table.
asList()
Get a list representation of the pivot table.
asJSON()
Get a JSON representation of the pivot table.
viewJSON()
View the JSON representation of the pivot table.
# NOT RUN {
# The package vignettes have many more 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()
# }
Run the code above in your browser using DataLab