A toolchain
for R.

A type checker and a fast runtime for R, written in Rust.

One toolchain

Checks, formats and navigates the R you have today.

R/pricing.R
fee_rate <- function(region) {
if (region == "north") 0.18 else 0.22
}
quote <- list(region = "north", amount = 1240.5)
fee <- quote$amount * fee_rate(quote$amount)
message("fee: " + fee)
$ ry check
type-mismatch
x expected a numeric value (`integer` or `double`), found `character`
--[R/pricing.R:7:9]
6 | fee <- quote$amount * fee_rate(quote$amount)
7 | message("fee: " + fee)
| ^^^^^^^
1 problem in 1 file

Plain R with no annotations: types are inferred, and the bug is found anyway.Checking guide

A backwards-compatible R runtime

Runs your R unchanged, and adds the types R is missing.

R/shapes.R
type Shape =
| :Circle(radius: double)
| :Square(side: double)
area <- function(shape: Shape) -> double {
match (shape) {
:Circle(radius = r) => {
pi * r^2
}
}
}
$ ry check
non-exhaustive-match
x this `match` does not handle `:Square(side = _)`: add an arm for it, or a catch-all `_ => ...` arm
--[R/shapes.R:6:3]
5 | area <- function(shape: Shape) -> double {
6 | match (shape) {
| ^^^^^^^^^^^^^
7 | :Circle(radius = r) => {

Take your R code into the future

Use ry today on the code you have, and move it to typed code one step at a time.

R, ry's additions, and strict modeTwo overlapping circles. The left circle is R: untyped code, S4, R6 and eval run, with names checked but types unknown. The right circle is what ry adds: records, tagged unions, typed tables, the standard library and inline types, which need ry. The overlap is typed R written with #: comments, which is checked and also runs on GNU R. Both circles together are R++, everything ry runs. The right circle alone is strict mode, R--, where only typed code is allowed.R++: everything ry runsRuntyped codeS4, R6, evaltypes unknowntyped R#: commentschecked, andruns on GNU Rry additionsrecordstagged unionstyped tablesstdlib, inline typesneeds rystrict mode (R--): only this circle

Works with the code you have todayAdjust your code, still backwards compatibleUse what ry adds, no longer runs on GNU RStrict mode (R--): only this circle

R/pricing.R
net_price <- function(price, rate) {
price * (1 - ratee)
}
net_price(100, 0.2)
$ ry check
unresolved
! I could not resolve `ratee` in this package, its imports, or builtins. Did you mean `rate`?
--[R/pricing.R:2:16]
1 | net_price <- function(price, rate) {
2 | price * (1 - ratee)
| ^^^^^
3 | }

Install

cargo install --git https://github.com/felix-andreas/ry ry-lang
ry check .