extendr_api::prelude

Derive Macro IntoDataFrameRow

Source
#[derive(IntoDataFrameRow)]
Expand description

Enable the construction of dataframes from arrays of structures.

§Example

use extendr_api::prelude::*;

#[derive(Debug, IntoDataFrameRow)]
struct MyStruct {
    x: i32,
    y: String,
}

let v = vec![MyStruct { x: 0, y: "abc".into() }, MyStruct { x: 1, y: "xyz".into() }];
let df = v.into_dataframe()?;

assert!(df.inherits("data.frame"));
assert_eq!(df[0], r!([0, 1]));
assert_eq!(df[1], r!(["abc", "xyz"]));