pharmaverse / pharmaverse/rtables
pruning functions are called twice on rows that are ultimately kept
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 260
- Forks
- 53
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at prune_table and trace the pruning flow using the afun and prun_fun example in the issue. Reproduce the duplicate calls, then verify that retained rows are evaluated once while the pruned row and final table remain correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100