Skip to main content

DataFrame

Struct DataFrame 

Source
pub struct DataFrame<T: IntoList> {
    rows: Vec<T>,
}
Expand description

Convert row-oriented data into a column-oriented R data.frame.

This type collects a sequence of row elements (structs implementing IntoList) and transposes them into column vectors suitable for creating an R data.frame.

§Example

use miniextendr_api::{miniextendr, convert::DataFrame};

#[derive(IntoList)]
struct Person {
    name: String,
    age: i32,
    height: f64,
}

#[miniextendr]
fn make_people() -> DataFrame<Person> {
    DataFrame::from_rows(vec![
        Person { name: "Alice".into(), age: 30, height: 165.0 },
        Person { name: "Bob".into(), age: 25, height: 180.0 },
        Person { name: "Carol".into(), age: 35, height: 170.0 },
    ])
}
// In R: make_people() returns a data.frame with 3 rows and columns: name, age, height

§Row-oriented to Column-oriented

R data frames are column-oriented (each column is a vector), but data is often produced row-by-row in Rust. DataFrame handles the transposition:

Input (row-oriented):           Output (column-oriented):
Row 1: {name: "A", age: 30}     name column:  ["A", "B", "C"]
Row 2: {name: "B", age: 25}  →  age column:   [30, 25, 35]
Row 3: {name: "C", age: 35}

Fields§

§rows: Vec<T>

Implementations§

Source§

impl<T: IntoList> DataFrame<T>

Source

pub fn from_rows(rows: Vec<T>) -> Self

Create a new DataFrame from a vector of row elements.

Source

pub fn new() -> Self

Create an empty DataFrame.

Source

pub fn push(&mut self, row: T)

Add a row to the data frame.

Source

pub fn len(&self) -> usize

Get the number of rows.

Source

pub fn is_empty(&self) -> bool

Check if empty.

Trait Implementations§

Source§

impl<T: Clone + IntoList> Clone for DataFrame<T>

Source§

fn clone(&self) -> DataFrame<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + IntoList> Debug for DataFrame<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: IntoList> Default for DataFrame<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: IntoList> FromIterator<T> for DataFrame<T>

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T: IntoList> IntoDataFrame for DataFrame<T>

Source§

fn into_data_frame(self) -> List

Convert this value into an R data.frame. Read more
Source§

impl<T: IntoList> IntoR for DataFrame<T>

IntoR implementation for DataFrame.

This allows DataFrame to be returned directly from #[miniextendr] functions.

Source§

type Error = Infallible

The error type for fallible conversions. Read more
Source§

fn try_into_sexp(self) -> Result<SEXP, Self::Error>

Try to convert this value to an R SEXP. Read more
Source§

unsafe fn try_into_sexp_unchecked(self) -> Result<SEXP, Self::Error>

Try to convert to SEXP without thread safety checks. Read more
Source§

fn into_sexp(self) -> SEXP

Convert this value to an R SEXP, panicking on error. Read more
Source§

unsafe fn into_sexp_unchecked(self) -> SEXP
where Self: Sized,

Convert to SEXP without thread safety checks, panicking on error. Read more

Auto Trait Implementations§

§

impl<T> Freeze for DataFrame<T>

§

impl<T> RefUnwindSafe for DataFrame<T>
where T: RefUnwindSafe,

§

impl<T> Send for DataFrame<T>
where T: Send,

§

impl<T> Sync for DataFrame<T>
where T: Sync,

§

impl<T> Unpin for DataFrame<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for DataFrame<T>

§

impl<T> UnwindSafe for DataFrame<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> RClone for T
where T: Clone,

Source§

fn clone(&self) -> T

Create a deep copy of this value.
Source§

impl<T> RDebug for T
where T: Debug,

Source§

fn debug_str(&self) -> String

Get a compact debug string representation.
Source§

fn debug_str_pretty(&self) -> String

Get a pretty-printed debug string with indentation.
Source§

impl<T> RDefault for T
where T: Default,

Source§

fn default() -> T

Create a new instance with default values.
Source§

impl<C, T> RFromIter<T> for C
where C: FromIterator<T>,

Source§

fn from_vec(items: Vec<T>) -> C

Create a new collection from a vector of items.
Source§

impl<T> ToDataFrameExt for T
where T: IntoDataFrame,

Source§

fn to_data_frame(self) -> ToDataFrame<Self>

Wrap self in ToDataFrame for R data.frame conversion.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.