Rust and R Integration

rustr is a Rust library that provides a Rust API to work with R.

Write pure Rust code with rustr , and then use rustinr R package to generate Rust interface in R. Run R script in Rust with rustr.

This project is now under construction. Issues and Pull requests are welcome!

Learn More


Safe

Guaranteed memory safety
Threads without data races

More Info

Fast

Zero-cost abstractions
minimal runtime ...

More Info

Easy

Just write Rust code
Roxygen is also supported

More Info

Rich

Thousand of packages
@ Crates.io & CRAN

More Info

Rust

pub fn fib_rust(a : i32) -> RResult<f64>{
    let mut first  = 0.0;
    let mut second = 1.0;
    let mut third  = 0.0;
    for _ in 0..a {
        third = first + second;
        first = second;
        second = third;
    }
    Ok(first)
}

microbenchmark(fib_rust(1000L))

// Unit: microseconds
//  min      lq   mean   median    uq    max neval
// 1.28    1.71   2.95     2.56  3.42  17.53   100

R

fib_r <- function(n) {
    first <- 0
    second <- 1
    third <- 0
    for (i in seq_len(n)) {
        third <- first + second
        first <- second
        second <- third
    }
    first
}

microbenchmark(fib_r(1000L))

#> Unit: microseconds
#>    min     lq   mean  median      uq    max neval
#> 772.73 782.57 800.51  798.61  806.73 934.81   100