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
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.
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()
┌───────┬────────┬──────────────┐
│ names ┆ values ┆ values_nulls │
│ --- ┆ --- ┆ --- │
│ str ┆ i32 ┆ i32 │
╞═══════╪════════╪══════════════╡
│ a ┆ 1 ┆ 1 │
│ b ┆ 2 ┆ null │
│ c ┆ 6 ┆ 3 │
└───────┴────────┴──────────────┘
- fork this template rpolars/extendrpolarsexamples
- clone your fork
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.
For a fully worked out demonstration of how to create a Rust + R library see here.