Optional Argument¶
To represent an optional argument, you can wrap it with Option. Then, the
corresponding R function sets the default value of NULL on the argument.
#[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()
}
}
This function works with or without the argument.