40 releases (5 breaking)

new 0.6.3 May 5, 2024
0.6.1 Apr 26, 2024
0.4.1 Mar 30, 2024
0.1.19 Dec 17, 2023
0.1.16 Oct 16, 2023

#4 in #savvy

Download history 72/week @ 2024-01-12 33/week @ 2024-01-19 137/week @ 2024-01-26 113/week @ 2024-02-02 514/week @ 2024-02-09 99/week @ 2024-02-16 65/week @ 2024-02-23 465/week @ 2024-03-01 801/week @ 2024-03-08 101/week @ 2024-03-15 587/week @ 2024-03-22 489/week @ 2024-03-29 270/week @ 2024-04-05 748/week @ 2024-04-12 196/week @ 2024-04-19 165/week @ 2024-04-26

1,402 downloads per month
Used in savvy

MIT license

94KB
2K SLoC

savvy-macro

Generate R-ready Rust functions by adding #[savvy] macro.

For the full details, please read savvy's crate documentation.

/// 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()
}

Dependencies

~295–740KB
~18K SLoC