Skip to contents

whence_table() is whence_trace() for a pipeline that ends in a table, such as group_by(region) |> summarise(total = sum(revenue)). The trace covers the table as a whole. whence_group() then explains one row of it: how many rows of its group each step removed, the code that makes that row, and the rows behind it.

Usage

whence_table(expr, env = parent.frame())

Arguments

expr

A pipeline that ends in a data frame.

env

The environment in which to evaluate expr.

Value

A whence_table object, which is also a whence_trace. Its value is the table. Its field keys names the group columns, or is NULL when the rows cannot be explained one by one.

Details

The rows of the table are the groups of its last summary step (summarise(), count() or tally()). A row can be explained when every group column of that step is still in the table.

Examples

library(dplyr, warn.conflicts = FALSE)

by_cyl <- whence_table(
  mtcars |>
    filter(hp > 90) |>
    group_by(cyl) |>
    summarise(mpg = mean(mpg))
)
by_cyl
#> <whence_table> 3 rows, one for each cyl
#> 
#> Where the rows went
#>   0 mtcars                  32
#>   1 -> hp > 90              27  -5 rows (16%)
#>   2 -> grouped by cyl       27
#>   3 -> grouped into 3 rows   3
#> 
#> Reproduce
#>   mtcars |>
#>     filter(hp > 90) |>
#>     group_by(cyl) |>
#>     summarise(mpg = mean(mpg))
whence_group(by_cyl, 2)
#> <whence_group> cyl = 6
#> 
#> Where the rows went
#>   0 mtcars                       7
#>   1 -> hp > 90                   7
#>   2 -> grouped by cyl            7
#>   3 -> summarised into this row  1
#> 
#> Reproduce
#>   mtcars |>
#>     filter(hp > 90) |>
#>     group_by(cyl) |>
#>     summarise(mpg = mean(mpg)) |>
#>     filter(cyl == 6)