#savvy #generate #macro #function #vector #r-ready

savvy-macro

通过添加 #[savvy] 宏来生成R-ready的Rust函数

42个版本 (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日

1461过程宏

Download history • Rust 包仓库 187/week @ 2024-04-22 • Rust 包仓库 312/week @ 2024-04-29 • Rust 包仓库 155/week @ 2024-05-06 • Rust 包仓库 224/week @ 2024-05-13 • Rust 包仓库 257/week @ 2024-05-20 • Rust 包仓库 242/week @ 2024-05-27 • Rust 包仓库 49/week @ 2024-06-03 • Rust 包仓库 107/week @ 2024-06-10 • Rust 包仓库 27/week @ 2024-06-17 • Rust 包仓库 69/week @ 2024-06-24 • Rust 包仓库 225/week @ 2024-07-01 • Rust 包仓库 56/week @ 2024-07-08 • Rust 包仓库 108/week @ 2024-07-15 • Rust 包仓库 64/week @ 2024-07-22 • Rust 包仓库 210/week @ 2024-07-29 • Rust 包仓库 48/week @ 2024-08-05 • Rust 包仓库

每月 451 次下载
savvy 中使用

MIT 许可证

100KB
2.5K SLoC

savvy-macro

通过添加 #[savvy] 宏来生成R-ready的Rust函数。

有关详细信息,请参阅 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()
}

依赖关系

~240–680KB
~16K SLoC