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 (const: unstable) · 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§

#[doc(hidden)]
fn into_named_columns(self) -> Vec<(String, SEXP)>
where Self: Sized,

Extract named column SEXPs from this DataFrame. 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> SizeEq<Cell<T>> for T
where T: ?Sized,

Source§

type CastFrom = CastFromWrapper

Source§

impl<T> SizeEq<ManuallyDrop<T>> for T
where T: ?Sized,

Source§

type CastFrom = CastFromWrapper

Source§

impl<T> SizeEq<MaybeUninit<T>> for T

Source§

impl<T> SizeEq<ReadOnly<T>> for T
where T: ?Sized,

Source§

type CastFrom = CastFromReadOnly

Source§

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

Source§

impl<T> SizeEq<Unalign<T>> for T

Source§

type CastFrom = CastFromWrapper

Source§

impl<T> SizeEq<UnsafeCell<T>> for T
where T: ?Sized,

Source§

type CastFrom = CastFromWrapper

Source§

impl<T> SizeEq<Wrapping<T>> for T

Source§

type CastFrom = CastFromWrapper

Source§

impl<T> SizedTypeProperties for T

Source§

#[doc(hidden)]
const SIZE: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGNMENT: Alignment = _

🔬This is a nightly-only experimental API. (ptr_alignment_type)
Source§

#[doc(hidden)]
const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
Source§

#[doc(hidden)]
const LAYOUT: Layout = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const MAX_SLICE_LEN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
The largest safe length for a [Self]. Read more
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.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> InvariantsEq<ManuallyDrop<T>> for T
where T: ?Sized,

Source§

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

Source§

impl<T> InvariantsEq<Unalign<T>> for T

Source§

impl<T> InvariantsEq<Wrapping<T>> for T

Source§

impl<Src, Dst, A, SV, DV, R> MutationCompatible<Src, A, SV, DV, (BecauseRead, R)> for Dst
where A: Aliasing, SV: Validity, DV: Validity, Src: Read<A, R> + ?Sized, Dst: Read<A, R> + ?Sized,

Source§

impl<Src, Dst, A, SV, DV> MutationCompatible<Src, A, SV, DV, BecauseInvariantsEq> for Dst
where A: Aliasing, SV: Validity, DV: Validity, Src: TransmuteFrom<Dst, DV, SV> + ?Sized, Dst: TransmuteFrom<Src, SV, DV> + InvariantsEq<Src> + ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> TransmuteFrom<Cell<T>, Valid, Valid> for T
where T: ?Sized,

Source§

impl<T> TransmuteFrom<ManuallyDrop<T>, Valid, Valid> for T
where T: ?Sized,

Source§

impl<T> TransmuteFrom<ReadOnly<T>, Valid, Valid> for T
where T: ?Sized,

Source§

impl<Src, Dst> TransmuteFrom<Src, Initialized, Initialized> for Dst
where Src: ?Sized, Dst: ?Sized,

Source§

impl<Src, Dst, V> TransmuteFrom<Src, V, Uninit> for Dst
where V: Validity, Src: ?Sized, Dst: ?Sized,

Source§

impl<Src, Dst> TransmuteFrom<Src, Valid, Initialized> for Dst
where Src: IntoBytes + ?Sized, Dst: ?Sized,

Source§

impl<T> TransmuteFrom<Unalign<T>, Valid, Valid> for T

Source§

impl<T> TransmuteFrom<UnsafeCell<T>, Valid, Valid> for T
where T: ?Sized,

Source§

impl<T> TransmuteFrom<Wrapping<T>, Valid, Valid> for T

Source§

impl<Src, Dst, A, SV, DV, C, R> TransmuteFromPtr<Src, A, SV, DV, C, R> for Dst
where A: Aliasing, SV: Validity, DV: Validity, C: CastExact<Src, Dst>, Dst: TransmuteFrom<Src, SV, DV> + TryTransmuteFromPtr<Src, A, SV, DV, C, R> + ?Sized, Src: ?Sized,

Source§

impl<Src, Dst, SV, DV, A, C, R> TryTransmuteFromPtr<Src, A, SV, DV, C, (BecauseMutationCompatible, R)> for Dst
where A: Aliasing, SV: Validity, DV: Validity, Src: TransmuteFrom<Dst, DV, SV> + ?Sized, Dst: MutationCompatible<Src, A, SV, DV, R> + ?Sized, C: CastExact<Src, Dst>,

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 24 bytes