41 个版本 (5 个破坏性更新)
0.6.5 | 2024年7月2日 |
---|---|
0.6.1 | 2024年4月26日 |
0.4.1 | 2024年3月30日 |
0.1.19 | 2023年12月17日 |
0.1.16 | 2023年10月16日 |
#193 in 文本处理
每月下载量 335
250KB
4.5K SLoC
Savvy - 使用 Rust 的简单 R 扩展接口
savvy 是一个使用 Rust 的简单 R 扩展接口,类似于 extendr 框架。名称“savvy”来源于日语单词“錆”(发音为 sàbí
),意为“Rust”。
使用 savvy,您可以从 Rust 代码自动生成 R 函数。以下是一个由 savvy 驱动的函数的示例
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/
贡献
示例
一个玩具示例 R 包可以在 R-package/
目录中找到。
感谢
Savvy 并非独一无二。这个项目在很大程度上受到了其他伟大项目的启发
依赖关系
~0.4–1.1MB
~24K SLoC