PivotBatchCalculator: R6 class that calculates the values for multiple cells in...

PivotBatchCalculatorR Documentation

R6 class that calculates the values for multiple cells in batches.

Description

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.

Format

R6Class object.

Details

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.

Active bindings

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.

Methods

Public methods


Method new()

Create a new 'PivotBatchCalculator' object.

Usage
PivotBatchCalculator$new(parentPivot = NULL)
Arguments
parentPivot

The pivot table that this 'PivotBatchCalculator' instance belongs to.

Returns

A new 'PivotBatchCalculator' object.


Method reset()

Reset the batch calculator, clearing all existing batches.

Usage
PivotBatchCalculator$reset()
Returns

No return value.


Method checkValidWorkingData()

Run some additional checks to see whether the working data is valid. Typically only used in development builds of the package.

Usage
PivotBatchCalculator$checkValidWorkingData(workingData = NULL)
Arguments
workingData

The working data to check.

Returns

No return value.


Method 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.

Usage
PivotBatchCalculator$isFiltersBatchCompatible(filters = NULL)
Arguments
filters

A 'PivotFilters' object that represents a set of filters to examine.

Details

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).

Returns

'TRUE' if the filters are batch compatible, 'FALSE' otherwise.


Method generateBatchesForNamedCalculationEvaluation1()

Generates a new batch or finds a relevant existing batch for a named calculation and single working filters object.

Usage
PivotBatchCalculator$generateBatchesForNamedCalculationEvaluation1(
  dataName = NULL,
  calculationName = NULL,
  calculationGroupName = NULL,
  workingFilters = NULL
)
Arguments
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.

Returns

The name of either the batch that was created or the relevant existing batch.


Method generateBatchesForNamedCalculationEvaluation2()

Generates one or more batches for the named calculations and set of working working data associated with a cell.

Usage
PivotBatchCalculator$generateBatchesForNamedCalculationEvaluation2(
  calculationName = NULL,
  calculationGroupName = NULL,
  workingData = NULL
)
Arguments
calculationName

The name of the calculation.

calculationGroupName

The calculation group of the calculation.

workingData

A list containing filter and/or filter overrides.

Details

A wrapper around 'generateBatchesForNamedCalculationEvaluation1()', which invokes this function as appropriate, depending on whether a calculation if either of type "summary" or type "calculation".

Returns

One or more batch names of either the batches that were created or the relevant existing batches.


Method generateBatchesForCellEvaluation()

Generates the batches for batch evaluation mode.

Usage
PivotBatchCalculator$generateBatchesForCellEvaluation()
Returns

One or more batch names of either the batches that were created or the relevant existing batches.


Method evaluateBatches()

Evaluate each of the batches defined in the batch calculator.

Usage
PivotBatchCalculator$evaluateBatches()
Returns

The number of batches that were evaluated.


Method getSummaryValueFromBatch()

Retrieve one calculation value from one batch, typically for the value of one cell in a pivot table.

Usage
PivotBatchCalculator$getSummaryValueFromBatch(
  batchName = NULL,
  calculationName = NULL,
  calculationGroupName = NULL,
  workingFilters = NULL
)
Arguments
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.

Returns

A single calculation value.


Method clone()

The objects of this class are cloneable with this method.

Usage
PivotBatchCalculator$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

# This class should only be created by the pivot table.
# It is not intended to be created outside of the pivot table.

pivottabler documentation built on Oct. 1, 2023, 5:07 p.m.