Giter Club home page Giter Club logo

extendr's Introduction

extendr - A safe and user friendly R extension interface using Rust.

Github Actions Build Status Crates.io Documentation License: MIT

Logo

Installation - Rust

Extendr is available on crates.io.

Simply add this line to the [dependencies] section of a rust crate. You will then be able to call R code from Rust.

[dependencies]
extendr-api = "0.2"

Installation - R

There are two ways you can use the extendr API from R. First, you can use the rextendr package to call individual Rust functions from an R session. Second, you can write an R package that uses compiled Rust code, see the helloextendr repo for a minimal example.

Overview

Extendr is a Rust extension mechanism for R

It is intended to be easier to use than the C interface and Rcpp as Rust gives type safety and freedom from segfaults.

The following code illustrates a simple structure trait which is written in Rust. The data is defined in the struct declaration and the methods in the impl.

use extendr_api::prelude::*;

struct Person {
    pub name: String,
}

#[extendr]
impl Person {
    fn new() -> Self {
        Self { name: "".to_string() }
    }

    fn set_name(&mut self, name: &str) {
        self.name = name.to_string();
    }

    fn name(&self) -> &str {
        self.name.as_str()
    }
}

#[extendr]
fn aux_func() {
}


// Macro to generate exports
extendr_module! {
    mod classes;
    impl Person;
    fn aux_func;
}

The #[extendr] attribute causes the compiler to generate wrapper and registration functions for R which are called when the package is loaded.

The extendr_module! macro lists the module name and exported functions and interfaces.

This library aims to provide an interface that will be familiar to first-time users of Rust or indeed any compiled language.

Anyone who knows the R library should be able to write R extensions.

Goals of the project

Instead of wrapping R objects, we convert to Rust native objects on entry to a function. This makes the wrapped code clean and dependency free. The ultimate goal is to allow the wrapping of existing Rust libraries without markup, but in the meantime, the markup is as light as possible.

#[extendr]
pub fn my_sum(v: &[f64]) -> f64 {
    v.iter().sum()
}

You can interact in more detail with R objects using the RObj type which wraps the native R object type. This supports a large subset of the R internals functions, but wrapped to prevent accidental segfaults and failures.

extendr roadmap

Basic

  • Be able to build simple rust extensions for R.
  • Wrap the R SEXP object safely (Robj)
  • Iterator support for matrices and vectors.
  • Class support.

Documentation

  • Begin documentation.
  • Begin book-form documentation.
  • Paper for Bioinformatics.
  • Build and publish CRAN R package.
  • Publish Use R! series book.

Automation

  • Auto-generate binding wrappers.
  • Auto-generate NAMESPACE and lib.R.

Features

  • Feature-gated support for ndarray.
  • Feature-gated support for rayon.

R packages

  • Bindings for rust-bio

Contributing

We are happy about any contributions!

To get started you can take a look at our Github issues.

You can also get in contact via our Discord server!

Development

The documentation for the latest development version is available here: https://extendr.github.io/extendr/extendr_api/

extendr's People

Contributors

andy-thomason avatar bicarlsen avatar brendanrbrown avatar cgmossa avatar clauswilke avatar dasmoth avatar dbdahl avatar dependabot[bot] avatar dfalbel avatar eitsupi avatar era127 avatar ericwburden avatar fdrennan avatar hobofan avatar ilia-kosenkov avatar josiahparry avatar lebensterben avatar multimeric avatar nickbp avatar programlyrique avatar shrektan avatar sorhawell avatar sstadick avatar stalkcomrade avatar yutannihilation avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.