Expand description
Reading R options (getOption()) from Rust.
Reading R options (getOption()) from Rust.
get_option reads one option and converts it with TryFromSexp.
A value that doesn’t convert is an RError whose message names the
option, so ? in a #[miniextendr] function returning Result<_, RError>
raises it with its classes:
ⓘ
use miniextendr_api::condition::RError;
use miniextendr_api::{get_option, miniextendr};
#[miniextendr]
pub fn report_width() -> Result<i32, RError> {
Ok(get_option::<i32>("mypkg.width")?.unwrap_or(80))
}options(mypkg.width = "wide")
report_width()
#> Error in report_width() :
#> options("mypkg.width") is invalid: expected integer, got characterRe-exports§
use crate::condition::RError;🔒use crate::from_r::SexpError;🔒use crate::from_r::TryFromSexp;🔒use crate::gc_protect::OwnedProtect;🔒use crate::sexp::SEXP;🔒
Constants§
- OPTION_
ERROR_ CLASS - The class every
get_optionconversion error carries.
Functions§
- get_
option - Read the R option
name, asgetOption(name)does, and convert it toT. - option_
error 🔒 - The error of an option
namewhose value didn’t convert: the refusal’s reason in R terms, its classes and fields kept when it carries its own.