R8

A type system for scientific computing, written in Rust.

  • TypesStructs and enums, declared in R
  • MethodsGenerics in R style, traits in Rust style
  • RulesChecks across fields, evaluated in Rust
  • FunctionsTyped arguments and typed results
  • TablesTyped columns, units, and rules over rows
  • SpeedValues built 30× faster than in S7
Installation, from r-universe
install.packages("R8", repos = c(
  "https://rtemis-org.r-universe.dev",
  "https://cloud.r-project.org"
))

The r-universe binaries need no Rust toolchain. The runtime is the Rust crate rtemis-r8.

What R8 provides

Four kinds of declaration, checked in Rust

Structs, enums, and traits

A struct holds named fields, each with a type, constraints, and a default. An enum holds one of its variants, each with fields of its own. A trait declares methods that a type implements, and a call dispatches on the type of its value.

  • Values are immutable R lists: a field write returns a new value that shares the unchanged fields.
  • An error lists every problem, with the field, the requirement, the value found, and the nearest allowed value.
  • Behavior is declared in R style, with generic() and implement(), or in Rust style, with new_trait() and impl().
  • A type declared in Rust with #[derive(R8)] can keep its values as Rust structs, with methods written in Rust.

Rules

A rule is an R expression over the fields of a type. R8 compiles it when the type is declared and evaluates it in Rust each time a value is made or a field that it reads is replaced.

  • A violation shows the message, the expression, and the values that it read.
  • Fields replaced together are checked once, after all of them.
  • A rule is a value: it checks a type, chooses the rows of a table with r8filter(), and combines with other rules through &, |, and !.

Typed functions

new_function() declares a function whose parameters have types, defaults, and rules, and whose result has a type. R8 checks the arguments before the body runs and the result after it; the body is plain R.

  • An error lists every problem of the call.
  • Rules hold across the parameters, as the rules of a struct hold across its fields.
  • In a package with Rust code, the body moves to Rust and the declaration stays in R, so callers see the same function.

Typed tables

A table type declares the columns of its values and rules across the columns of each row. R8 checks them in Rust, over the vectors of R.

  • Raven holds any columns; new_table_type() declares a table type, whose values have the declared columns.
  • A column declares its type, range, allowed values, missing cells, distinct values, unit, and description.
  • An error names the rule, the row, and the cells that it read.
  • The package R8.io reads and writes CSV, TSV, and Parquet files as R8 tables.

Benchmarks

R8 against S7, on the same type

Every system declares GBM, the settings of a gradient boosting machine, with twelve checked fields and two rules across fields. Each figure is a median; lower is less time or less memory.

Construction of a value
30×S7 / R8
R8
4.06 µs
S7
120 µs
S3
24.3 µs
Whole-value validation
33×S7 / R8
R8
2.42 µs
S7
81 µs
S3
22.1 µs
200 types usable after load
29×S7 / R8
R8
9 ms
S7
265 ms
S3
10 ms
Peak memory of a package of 200 types
27×S7 / R8
R8
6.09 MB
S7
162 MB
S3
0.828 MB

The third figure of each card is that of the system with the lowest figure among S3, S4, RC, R6, and S7. One run at commit cc22440 on 2026-11-21: Apple M5, 32 GB, macOS 27.2; R 4.6.2, R8 0.4.0, S7 1.0.0. The guide's chapter shows every system on eleven measurements, with the code that each one times.

Benchmarks, in the guide

Documentation

The R8 guide

The examples of the guide come from machine learning: most build on one case, a resampler that splits a dataset into training and test sets, in R style and in Rust style.

docs.rtemis.org/r/r8