Call Rust code from R rextendr logo

R build
status CRAN
status Lifecycle:
stable codecov


To install the package, run:


Note that this will install the package but does not guarantee that the package can do anything useful. You will also need to set up a working Rust toolchain. See the installation instructions for libR-sys for help. If you can successfully build libR-sys you’re good.


Basic use example:


# create a Rust function
rust_function("fn add(a:f64, b:f64) -> f64 { a + b }")

# call it from R
add(2.5, 4.7)
#> [1] 7.2

The package also enables a new chunk type for knitr, extendr, which compiles and evaluates Rust code. For example, a code chunk such as this one:

rprintln!("Hello from Rust!");

let x = 5;
let y = 7;
let z = x*y;


would create the following output in the knitted document:

rprintln!("Hello from Rust!");

let x = 5;
let y = 7;
let z = x*y;

#> Hello from Rust!
#> [1] 35

See also

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Try the rextendr package in your browser

Any scripts or data that you put into this service are public.

rextendr documentation built on May 31, 2023, 5:37 p.m.