Skip to main content

Module options

Module options 

Source
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 character

Re-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_option conversion error carries.

Functions§

get_option
Read the R option name, as getOption(name) does, and convert it to T.
option_error 🔒
The error of an option name whose value didn’t convert: the refusal’s reason in R terms, its classes and fields kept when it carries its own.