Skip to content

pruning functions are called twice on rows that are ultimately kept #1036

@gmbecker

Description

@gmbecker

Consider a silly table:

afun <- function(df, .var) {
  vals <- tapply(df[[.var]], df$Species, mean)
  in_rows(.list = vals)
}
lyt <- basic_table() |>
    analyze("Sepal.Width", afun = afun)
tbl <-  build_table(lyt, iris)
> tbl
             all obs
————————————————————
setosa        3.428 
versicolor    2.77  
virginica     2.974 

With a pruning function which prunes rows whose values are less than 2.8 (so 2 will be kept and one will be pruned)

prun_fun <- function(tt) {
  print(obj_name(tt))
  unlist(cell_values(tt)) < 2.8
}

our pruning function is only called once on the row that is pruned, but is called twice on the ones that are kept:

> prune_table(tbl, prun_fun)
[1] "setosa"
[1] "versicolor"
[1] "virginica"
[1] "setosa"
[1] "virginica"
            all obs
———————————————————
setosa       3.428 
virginica    2.974 

This isn't an issue of incorrect results (provide the pruning function is deterministic, which it really should be), but it is kind of silly that we are doing an identical thing twice. This (can be) much more of a real issue while #1035 remains unresolved, as that can make pruning functions overly expensive.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions