Skip to main content

list

Macro list 

Source
list!() { /* proc-macro */ }
Expand description

Construct an R list from Rust values.

This macro provides a convenient way to create R lists in Rust code, using R-like syntax. Values are converted to R objects via the IntoR trait.

§Syntax

// Named entries (like R's list())
list!(
    alpha = 1,
    beta = "hello",
    "my-name" = vec![1, 2, 3],
)

// Unnamed entries
list!(1, "hello", vec![1, 2, 3])

// Mixed (unnamed entries get empty string names)
list!(alpha = 1, 2, beta = "hello")

// Empty list
list!()

§Examples

use miniextendr_api::{list, IntoR};

// Create a named list
let my_list = list!(
    x = 42,
    y = "hello world",
    z = vec![1.0, 2.0, 3.0],
);

// In R this is equivalent to:
// list(x = 42L, y = "hello world", z = c(1, 2, 3))