Exploring R and Rust in Bioinformatics

Thank you!

About Mossa

  • Maintainer & Lead Developer of extendr
  • PhD Veterinary Epidemiology
  • Postdoc @ Københavns Universitet - University of Copenhagen

About Josiah

  • Sr. Product Engineer @ Esri
  • Spatial Statistician
  • Building R packages for the R-ArcGIS Bridge

What is extendr?

extending R with Rust

What is extendr?

  • Include Rust into R packages
  • Akin to Rcpp & cpp11

What even is Rust?

  • Low-level language
  • Modern day equivalent to C++
  • Memory safe-er
  • Developer friendly

Scientific computing with Rust is growing

extendr is comprised of:

extendr packages

  • 16 CRAN packages
  • Many, many more on GitHub

380k downloads and counting

Why Rust?

  • Easy to make bindings

Blazingly fast

The compiler is nice

The compiler is nice

Easy (enough) to refactor

Broaden your reach

Quick to pickup

A little skill goes a long way

Example: single

#[extendr]
fn gh_encode(x: f64, y: f64, length: usize) -> String {
    let coord = Coord { x, y };
    encode(coord, length).expect("Failed to encode the geohash")
}

Example: vectorize

#[extendr]
fn gh_encode(x: &[f64], y: &[f64], length: usize) -> Vec<String> {
    x
        .into_iter() 
        .zip(y.into_iter()) 
        .map(|(xi, yi)| { 
            let coord = Coord { x: xi, y: yi };
            encode(coord, length)
                .expect("Failed to encode the geohash")
        })
        .collect::<Vec<_>()
}

Example: parallelize

#[extendr]
fn gh_encode(x: &[f64], y: &[f64], length: usize) -> Vec<String> {
    x
        .into_iter()
        .zip(y.into_iter())
        .par_bridge() // convert into a parallel iterator
        .with_min_len(1024) // set minimum parallel chunk length
        .map(|(xi, yi)| {
            let coord = Coord { x: xi, y: yi };
            encode(coord, length)
                .expect("Failed to encode the geohash")
        })
        .collect::<Vec<_>()
}

extendr in bioformatics

WebGestaltR:

metabodecon

mspredictr

viewmastR

extendr across-language

Phylo2Vec

Exon

and even more