Expand description
§Savvy - A Simple R Interface
savvy is a simple R extension interface using Rust, like the extendr framework.
The name “savvy” comes from the Japanese word “錆” (pronounced as sàbí
), which means “Rust”.
With savvy, you can automatically generate R functions from Rust code. This is an example of what a savvy-powered function would look like.
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"
§User guide
Re-exports§
pub use error::Error;
pub use error::Result;
pub use sexp::environment::EnvironmentSexp;
pub use sexp::external_pointer::get_external_pointer_addr;
pub use sexp::external_pointer::take_external_pointer_value;
pub use sexp::external_pointer::ExternalPointerSexp;
pub use sexp::external_pointer::IntoExtPtrSexp;
pub use sexp::function::FunctionArgs;
pub use sexp::function::FunctionSexp;
pub use sexp::integer::IntegerSexp;
pub use sexp::integer::OwnedIntegerSexp;
pub use sexp::list::ListSexp;
pub use sexp::list::OwnedListSexp;
pub use sexp::logical::LogicalSexp;
pub use sexp::logical::OwnedLogicalSexp;
pub use sexp::na::NotAvailableValue;
pub use sexp::null::NullSexp;
pub use sexp::numeric::NumericScalar;
pub use sexp::numeric::NumericSexp;
pub use sexp::numeric::NumericTypedSexp;
pub use sexp::raw::OwnedRawSexp;
pub use sexp::raw::RawSexp;
pub use sexp::real::OwnedRealSexp;
pub use sexp::real::RealSexp;
pub use sexp::string::OwnedStringSexp;
pub use sexp::string::StringSexp;
pub use sexp::Sexp;
pub use sexp::TypedSexp;
pub use sexp::complex::ComplexSexp;
pub use sexp::complex::OwnedComplexSexp;
pub use unwind_protect::unwind_protect;
pub use eval::assert_eq_r_code;
pub use eval::eval_parse_text;
pub use eval::EvalResult;
Modules§
Macros§
Functions§
Type Aliases§
- Alias for a
Complex<f64>