1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//! R wrappers over structures within the `graph` module
use extendr_api::*;
use crate::graph::leiden::LeidenParams;
use crate::prelude::*;
//////////////////
// LeidenParams //
//////////////////
impl LeidenParams {
/// Parse the [LeidenParams] from an R list.
///
/// Missing keys fall back to [LeidenParams::default]. Recognised keys:
/// `resolution`, `beta`, `n_iterations`, `refine` and `seed`.
///
/// ### Params
///
/// * `r_list` - The R list to parse
///
/// ### Returns
///
/// The [LeidenParams], or an error when a value is present but unusable.
pub fn from_r_list(r_list: List) -> Result<Self> {
let params = r_list_to_map(r_list)?;
let defaults = Self::default();
Ok(Self {
resolution: r_list_real(¶ms, "resolution")?.unwrap_or(defaults.resolution),
beta: r_list_real(¶ms, "beta")?.unwrap_or(defaults.beta),
n_iterations: r_list_count(¶ms, "n_iterations")?.unwrap_or(defaults.n_iterations),
refine: params
.get("refine")
.and_then(|v| v.as_bool())
.unwrap_or(defaults.refine),
seed: r_list_count_allow_zero(¶ms, "seed")?
.map(|v| v as u64)
.unwrap_or(defaults.seed),
})
}
}