Skip to content

Latest commit

 

History

History
89 lines (62 loc) · 2.53 KB

README.md

File metadata and controls

89 lines (62 loc) · 2.53 KB

TEMPLATE: extend polars (the R package) with rust

Installation

Install R package polars e.g. from binary. Also needed for end user

  install.packages("polars", repos = "https://rpolars.r-universe.dev")

Install rextendr R package to assist write R bindings for your rust project. See extendr github page or visit the discord to ask questions.

  install.packages("rextendr")

s

System dependencies

To install the full version of rust-polars you will need rust nightly e.g. this version. Stable is also possible, check with rust-polars docs.

  • Install rustup, the cross-platform Rust installer. Then:

    rustup toolchain install nightly-2023-05-07
    rustup default nightly-2023-05-07
  • Windows: Make sure the latest version of Rtools is installed and on your PATH.

  • MacOS: Make sure Xcode is installed.

  • Install CMake and add it to your PATH.

Build templates

Once Rust is working, you can build this

remotes::install_github("rpolars/extendrpolarsexamples")

After installation, the following should work:

library(extendrpolarsexamples)

# zero-copy export a rust-polars DataFrame to valid r-polars DataFrame
extendrpolarsexamples::make_df()
┌───────┬────────┬──────────────┐
│ namesvaluesvalues_nulls │
│ ---------          │
│ stri32i32          │
╞═══════╪════════╪══════════════╡
│ a11            │
│ b2null         │
│ c63            │
└───────┴────────┴──────────────┘

Development

  • fork this template rpolars/extendrpolarsexamples
  • clone your fork

Generate wrappers

When you make either of the following changes to the Rust source code, you'll need to regenerate the wrappers.

  • add a new function
  • modify the signature of an existing function
  • modify the documentation written on Rust code (on the lines starting with ///)

This can be done by:

  rextendr::document()

Which will compile the Rust code as well as updating documentation.

More rextendr help

For a fully worked out demonstration of how to create a Rust + R library see here.