r8explain(call) takes a call of r8map(), r8summarize(), or r8set(),
unevaluated, and returns its plan: the stages of the call, where each runs, in
Rust or in R, the typed function that each calls and the language of its body,
the calls, and the stages that each reads. It evaluates the call's arguments in
the caller's frame, runs the function's checks, compiles its expressions against
the table, and numbers the groups of the rows, then stops before it evaluates a
row or calls a typed function.
Usage
r8explain(call)
# S3 method for class 'r8_plan'
as.data.frame(x, row.names = NULL, optional = FALSE, ...)
# S3 method for class 'r8_plan'
format(x, form = c("text", "mermaid"), ...)
# S3 method for class 'r8_plan'
print(x, ...)Arguments
- call
A call of
r8map(),r8summarize(), orr8set(), unevaluated.- x
An
r8_plan.- row.names, optional
Not used.
- ...
Not used.
- form
Character {"text", "mermaid"}: The plan's headline and stages, or its Mermaid flowchart.
Value
An r8_plan: a list of engine, the languages of the call's work,
"rust", "r", or "rust+r"; headline, the call's summary in the words
of r8map()'s start line; and nodes, the call's node, then one node for
each stage, each with the members of rtemis's session records: node_id
("s1", "s2", ...), parent_id, kind (the function, then "r8.check",
"r8.compile", ...), label, status ("pending"), t_start, t_end,
and meta. The call's meta holds the call, R8's version, the record's
format, the plan hash, the threads, the platform, and each typed function's
name and body's language with its body's identity: the package and its
version, or, for a function of no package, body_hash, the SHA-256 of its
body as R deparses it. The plan hash covers the table type's declaration, the
expressions, the keys, and the typed functions' declarations, and not their
bodies, so that it is the same for a body in R and in Rust. An equal plan
hash, equal body identities, and equal inputs give an equal result. A stage's
meta holds its engine, the stages that it reads (inputs), whether it may
run on worker threads, and its counts; in the plan of a run, busy, the
seconds that it worked, and, for a stage that failed, message and, where
it has them, group and row, the group and its first row, from 1, or,
for a map over items, row, the item.
as.data.frame() gives one row for each stage:
node_id, stage, label, engine, function and language, of the
typed function that a call stage calls, calls, threads, inputs,
status, and, for the plan of a run that r8bench() collects, t_start,
t_end, and busy, seconds, which are NA before a run. format(plan)
gives the lines that print() writes, and format(plan, "mermaid") the
plan's Mermaid flowchart, as one string, in which each stage's class is its
engine, rust or r.
Stages
A call over the columns of a table has the stages check, the checks of its
arguments, in R; compile, of its expressions against the table's columns;
group, of the rows by the key columns; aggregate, of the aggregates of the
dialect, which may run on worker threads; a call stage for each call of a typed
function in each expression, in the language of the function's body, with an
ordinal where an expression calls one function twice; evaluate, of the rows of
an expression that reads cells outside its aggregates and calls; and assemble,
of the result, in R. A stage's inputs are the stages whose results it reads: a
call whose arguments read an aggregate reads aggregate, evaluate reads the
aggregates and calls of the expressions of rows, and assemble reads the stages
that no other stage reads. A map over the items of a list or a vector has
check, call, and assemble, and R makes its calls. The engine of the call,
"rust", "r", or "rust+r", is that of its evaluation and its calls, as the
messages of r8map() state it. Where a table function's checks call another,
the first that R8 enters is the call explained.
What a plan does not state
What the body of a typed function in R does inside, and whether a body in Rust
calls R. r8rust_signature() writes the signature of a body in Rust for a
function whose body is in R.
Examples
op <- options(r8.namespace = "demo")
m <- Raven(
combo = c(1L, 1L, 2L, 2L),
auc = c(0.81, 0.79, 0.85, 0.88),
brier = c(0.16, 0.18, 0.14, 0.12)
)
spread <- new_function(
"spread",
function(x = arg_vec(type_double())) max(x) - min(x),
return_type = type_double()
)
plan <- r8explain(r8map(m, spread, by = "combo"))
plan#> <r8 plan> r8map(): demo::spread over 2 columns and 2 groups, 4 calls, in Rust, with the body of `demo::spread` in R
#> s2 R check
#> s3 Rust compile, 2 expressions
#> s4 Rust group by combo, 2 groups
#> s5 R call demo::spread: auc, 2 calls
#> s6 R call demo::spread: brier, 2 calls
#> s7 R assemble
#> A body in R runs on R's thread; r8rust_signature(spread) writes the signature of its body in Rust.
#> The plan does not state what a body in R does inside, or whether a body in Rust calls R.plan$engine#> [1] "rust+r"as.data.frame(plan)#> node_id stage label engine function language calls
#> 1 s2 check r <NA> <NA> NA
#> 2 s3 compile rust <NA> <NA> NA
#> 3 s4 group by combo rust <NA> <NA> NA
#> 4 s5 call demo::spread: auc r demo::spread r 2
#> 5 s6 call demo::spread: brier r demo::spread r 2
#> 6 s7 assemble r <NA> <NA> NA
#> threads inputs status t_start t_end busy
#> 1 FALSE pending NA NA NA
#> 2 FALSE s2 pending NA NA NA
#> 3 FALSE s2 pending NA NA NA
#> 4 FALSE s3, s4 pending NA NA NA
#> 5 FALSE s3, s4 pending NA NA NA
#> 6 FALSE s5, s6 pending NA NA NA#> flowchart LR
#> subgraph s1["r8map(): demo::spread"]
#> s2["check"]:::r
#> s3["compile, 2 expressions"]:::rust
#> s4["group by combo, 2 groups"]:::rust
#> s5["call demo::spread: auc, 2 calls"]:::r
#> s6["call demo::spread: brier, 2 calls"]:::r
#> s7["assemble"]:::r
#> end
#> s2 --> s3
#> s2 --> s4
#> s3 --> s5
#> s4 --> s5
#> s3 --> s6
#> s4 --> s6
#> s5 --> s7
#> s6 --> s7options(op)