Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider options for editing a pivot table after it has been calculated #56

Open
cbailiss opened this issue Jul 14, 2020 · 0 comments
Open

Comments

@cbailiss
Copy link
Owner

For background, see:
https://stackoverflow.com/questions/62452034/can-we-replace-a-column-from-a-pivot-table-created-using-pivottabler-package

Example that doesn't work:

removeAllColumnGroups <- function(pt)
{
  while(pt$columnGroup$childGroupCount > 0) {
    pt$columnGroup$removeChildGroup(index=pt$columnGroup$childGroupCount)
  }
}

pt <- PivotTable$new()
pt$addData(bhmtrains)
pt$addColumnDataGroups("TrainCategory")
pt$addRowDataGroups("TOC")
pt$defineCalculation(calculationName="TotalTrains", summariseExpression="n()")
pt$renderPivot()

removeAllColumnGroups(pt)
pt$renderPivot()

# need to reapply the calculations as those cells have been lost
pt$addColumnDataGroups("TrainCategory")
pt$defineCalculation(calculationName="TotalTrains", summariseExpression="n()")
pt$renderPivot()

Is there an easy way to clear the cells from the pivot table (to allow the rows and columns to be amended) then reapply the calculations (on the same axis as they were originally applied, in the same order?)

Or is all this just too complicated and not worth doing?

Consider adding pt$clearColumnGroups(), pt$clearRowGroups().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant