yutannihilation / savvy

A simple R extension interface using Rust
https://yutannihilation.github.io/savvy/guide/
MIT License
70 stars 4 forks source link

Support optional args represented by `Option<T>` #243

Closed yutannihilation closed 5 months ago

yutannihilation commented 5 months ago

Close #242

Rust:

#[savvy]
fn default_value_vec(x: Option<IntegerSexp>) -> savvy::Result<Sexp> {
    if let Some(x) = x {
        x.iter().sum::<i32>().try_into()
    } else {
        (-1).try_into()
    }
}

R:

default_value_vec <- function(x = NULL) {
  ...snip...
}
default_value_vec(1:10)
#> [1] 55

default_value_vec()
#> [1] -1