r8map(x, f, columns, by) gives one row for each group of the rows by by: the keys, then f of each column of columns, under the column’s name. Without columns, every column that is not a key is mapped.
11.1 A typed function
f is a typed function of one column. It is called on the cells of each column in each group, as a direct call is, and returns one value of its declared type:
trimmed_mean <-new_function("trimmed_mean",function(x =arg_vec(type_double())) mean(x, trim =0.1),return_type =type_double())r8map(metrics, trimmed_mean, columns = metric_names, by ="param_combo_id")
Its arguments are checked as those of a direct call: a group with a missing cell is an error unless the parameter’s type is option(), and the function handles the missing cells, with its own na.rm where it has one. The map is that of calc(trimmed_mean(col())), below: a body in Rust is called from R8’s Rust code, and a body in R in one loop of R for each column. The body may move to Rust, and the call stays as it is.
A typed function with other parameters is called inside calc(), where col() is the column mapped and the other arguments are constants:
trimmed <-new_function("trimmed",function(x =arg_vec(type_double()), trim =arg_double(default =0)) mean(x, trim = trim),return_type =type_double())r8map(metrics, calc(trimmed(col(), trim =0.2)), columns = metric_names, by ="param_combo_id")
The expression may combine aggregates, as a mean of each metric weighted by another column, calc(sum(col() * n_test) / sum(n_test)).
11.3 Lists and vectors
The items of a list or a vector are its elements, each given to the first parameter of a typed function. args holds the constant arguments of every call, checked against the function’s parameters before the first call.
A tuner fits one model for each resample. A resample is a set of indices of the training rows, and the data is a constant argument, so that each call gathers its own rows:
One fold’s rows exist only during its call, and the data is given once, however many folds there are. A list of index vectors serves the same way, with arg_vec(type_integer()) as the first parameter.
The return type gives the container: a scalar type an atomic vector, and another type a list of the values, with the names of x. A call that fails names its item, and the map gives nothing:
Groups that a column’s values define, such as one model for each combination of hyperparameters, are the tables that split() gives, each with its group’s rows:
split() builds the tables of every group before the first call; a resample, whose rows are indices, needs no table of its own until its call.
11.4 Progress
A map of a typed function reports its progress to a host that draws it: the option r8.progress holds three functions, begin(total, label, kind), which gives a handle, update(handle, current), and end(handle, status). The total is the calls of the function, on a table its groups times its columns, the label its name, and the kind "r8map". A map that ends within 0.2 s reports nothing, and a longer one reports at most about every 0.05 to 0.2 s, so that the hook costs nothing measurable beside a model’s fit. rtemis.core draws it, nested under the progress that is open:
Without the option, its default, a map reports no progress. A fifth function, stages(handle, plan), receives the plan of the map’s run before end() (The resources of a run).
11.5 Messages
At verbosity = 1L, the default, a map that takes longer than 0.2 s writes a line once it has run for 0.2 s and a line when it completes. Each states where the map runs: in Rust, or in Rust with the body of a typed function in R, for a table; in R, for a list. The last line states the wall time, the CPU time of the R process, and the threads that the map may use:
r8map(metrics, fit_metric, by ="param_combo_id")#> 2026-11-27 10:04:12 r8map(): pkgr::fit_metric over 3 columns and 100,000 groups, 300,000 calls, in Rust, with the body of `pkgr::fit_metric` in R [r8map]#> 2026-11-27 10:04:15 r8map(): completed in 3.3 s, CPU 3.2 s of 2 threads, in Rust, with the body of `pkgr::fit_metric` in R [r8map]
The lines are R’s messages, which suppressMessages() silences, and verbosity = 0L writes none. A hook in r8.progress with the fourth function message(event) receives each line as a list of level, phase ("start" or "end"), text, caller, and time, as rtemis.core’s msg() takes it above; a hook of three functions receives begin and end in their place. The words of the lines are R8’s Rust code’s, the same in every host.
11.6 The plan of a map
r8explain(call) gives the plan of a call of r8map(), r8summarize(), or r8set() before it runs: its stages, where each runs, the typed function that each calls and the language of its body, and the calls. It evaluates the arguments, runs the function’s checks, compiles the expressions, and numbers the groups, then stops before it calls a typed function:
plan <-r8explain(r8map(metrics, trimmed_mean, columns = metric_names, by ="param_combo_id"))plan
<r8 plan> r8map(): demo::trimmed_mean over 3 columns and 4 groups, 12 calls, in Rust, with the body of `demo::trimmed_mean` in R
s2 R check
s3 Rust compile, 3 expressions
s4 Rust group by param_combo_id, 4 groups
s5 R call demo::trimmed_mean: auc, 4 calls
s6 R call demo::trimmed_mean: balanced_accuracy, 4 calls
s7 R call demo::trimmed_mean: brier, 4 calls
s8 R assemble
A body in R runs on R's thread; r8rust_signature(trimmed_mean) 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 is "rust", "r", or "rust+r": a test can assert that a call whose bodies have moved to Rust runs in Rust alone. as.data.frame(plan) gives the stages as a table, and format(plan, "mermaid") the plan as a Mermaid flowchart, in which each stage’s class is where it runs:
The plan does not state what a body in R does inside, or whether a body in Rust calls R. Its first node holds the call, R8’s version, the threads, the platform, each typed function’s body’s identity, and the plan hash: the SHA-256 of the table type’s declaration, the expressions, the keys, and the declarations of the typed functions. The hash covers what R8 declares of the call, and is the same for a body in R and in Rust. A body’s identity is its package and version, or, for a function of no package, body_hash, the SHA-256 of its body as R deparses it. An equal plan hash, equal body identities, and equal inputs give an equal result.
11.7 The resources of a run
r8bench(expr) evaluates expr once and gives the resources that it took: the wall time, the CPU time of R’s process, the most memory that the process held, and the cores that it may use. For each call of r8map(), r8summarize(), or r8set() that expr runs, it keeps the plan of the call, filled by its run: each stage’s status, its first start and last end in seconds from the call’s start, and the seconds it was busy.
b <-r8bench(r8map(metrics, trimmed_mean, columns = metric_names, by ="param_combo_id"))b
r8bench(): 0.64 ms, CPU 0.67 ms (1.0 of 5 threads), memory peak 171 MiB, in Rust and R
stage engine status t_start t_end busy
1 check r completed 0.000000000 0.000177083 0.000177083
2 compile rust completed 0.000181500 0.000188458 0.000006958
3 group rust completed 0.000177083 0.000181500 0.000004417
4 call r completed 0.000226250 0.000301833 0.000075583
5 call r completed 0.000303458 0.000352042 0.000048584
6 call r completed 0.000352500 0.000396625 0.000044125
7 assemble r completed 0.000463083 0.000512666 0.000049583
The CPU time is that of all the threads of R’s process; b$utilization is its ratio to the wall time, the threads busy on average. b$rss_peak is the most memory that the process held during expr, read about every 10 ms by a thread of Rust. r8bench(expr, gc = TRUE) collects R’s heap before expr and gives in b$r_heap_peak the most that R’s heap held during it. A failed stage holds its group, the group’s first row, and the message, and the stages after it stay pending.
Only a run whose plan is collected builds and times it: inside r8bench(), or under a progress hook with the function stages(handle, plan), which receives the plan of the map’s run before end().
11.8 A generic
r8map() is a generic of R8 that dispatches on the table and on what f is. A method for Raven applies to every table, after a method for the table’s own type, so that a package can declare a map of its own types. A plain R function is an error that names the typed form; lapply(x[columns], f) applies an R function to whole columns, and split() gives the tables of the groups:
r8map(metrics, median, by ="param_combo_id")
Error:
! r8map() maps a typed function of R8, declared with new_function(), whose return type gives the container of the results, or, over the columns of a table, calc() with col(). lapply(x, f) applies an R function, and split() gives the tables of a table's groups.