Crates.io | savvy |
lib.rs | savvy |
version | 0.8.0 |
source | src |
created_at | 2023-09-25 13:46:39.396278 |
updated_at | 2024-10-31 01:00:54.659245 |
description | A simple R extension interface |
homepage | |
repository | https://github.com/yutannihilation/savvy/ |
max_upload_size | |
id | 982725 |
size | 284,202 |
savvy is a simple R extension interface using Rust, like the
extendr framework. The name “savvy” comes
from the Japanese word “錆” (pronounced as sàbí
), which means “Rust”.
With savvy, you can automatically generate R functions from Rust code. This is an example of what a savvy-powered function would look like:
Rust
use savvy::savvy;
/// Convert to Upper-case
///
/// @param x A character vector.
/// @export
#[savvy]
fn to_upper(x: StringSexp) -> savvy::Result<savvy::Sexp> {
// Use `Owned{type}Sexp` to allocate an R vector for output.
let mut out = OwnedStringSexp::new(x.len())?;
for (i, e) in x.iter().enumerate() {
// To Rust, missing value is an ordinary value. In `&str`'s case, it's just "NA".
// You have to use `.is_na()` method to distinguish the missing value.
if e.is_na() {
// Set the i-th element to NA
out.set_na(i)?;
continue;
}
let e_upper = e.to_uppercase();
out.set_elt(i, e_upper.as_str())?;
}
out.into()
}
R
to_upper(c("a", "b", "c"))
#> [1] "A" "B" "C"
https://yutannihilation.github.io/savvy/guide/
A toy example R package can be found in R-package/
directory.
Savvy is not quite unique. This project is made possible by heavily taking inspiration from other great projects: