pub struct DataFrameView {
inner: NamedList,
nrow: usize,
}Expand description
A validated R data.frame backed by NamedList for O(1) column access.
This type wraps an existing R data.frame SEXP and provides:
- O(1) column access by name via the
NamedListindex - O(1) column access by position
- Schema validation via
TypedListSpec - Conversion back to
NamedListor raw SEXP
§Construction
Use DataFrameView::from_sexp to wrap an existing R data.frame, or
NamedList::as_data_frame / List::as_data_frame to promote a list.
§Relationship to DataFrame<T>
DataFrame<T> is for creating data frames from
row-oriented Rust data (implements IntoDataFrame). DataFrameView is for
receiving data frames from R and inspecting their contents.
Fields§
§inner: NamedList§nrow: usizeImplementations§
Source§impl DataFrameView
impl DataFrameView
Sourcepub fn from_sexp(sexp: SEXP) -> Result<Self, DataFrameError>
pub fn from_sexp(sexp: SEXP) -> Result<Self, DataFrameError>
Wrap an existing R data.frame SEXP.
Validates that the object:
- Is a VECSXP (list)
- Inherits from
"data.frame" - Has a
namesattribute - Has extractable
row.namesfor nrow
§Errors
Returns DataFrameError if validation fails.
Sourcefn from_named_list(inner: NamedList, nrow: usize) -> Self
fn from_named_list(inner: NamedList, nrow: usize) -> Self
Construct an DataFrameView from a NamedList and a pre-validated nrow.
This is used internally by NamedList::as_data_frame after validation.
Sourcepub fn column_index<T>(&self, idx: usize) -> Option<T>where
T: TryFromSexp<Error = SexpError>,
pub fn column_index<T>(&self, idx: usize) -> Option<T>where
T: TryFromSexp<Error = SexpError>,
Get a column by 0-based index, converting to type T.
Returns None if the index is out of bounds or conversion fails.
Sourcepub fn column_raw(&self, name: &str) -> Option<SEXP>
pub fn column_raw(&self, name: &str) -> Option<SEXP>
Get the raw SEXP for a column by name.
Returns None if the column name is not found.
Sourcepub fn names(&self) -> impl Iterator<Item = &str>
pub fn names(&self) -> impl Iterator<Item = &str>
Iterate over column names (unordered, from the HashMap index).
Sourcepub fn contains_column(&self, name: &str) -> bool
pub fn contains_column(&self, name: &str) -> bool
Check if a column name exists.
Sourcepub fn validate(
&self,
spec: &TypedListSpec,
) -> Result<TypedList, TypedListError>
pub fn validate( &self, spec: &TypedListSpec, ) -> Result<TypedList, TypedListError>
Validate the data frame’s column types against a TypedListSpec.
This bridges the typed_list validation infrastructure
to data frames, allowing schema checks like:
let spec = TypedListSpec::new(vec![
TypedEntry::required("x", TypeSpec::Numeric(None)),
TypedEntry::required("y", TypeSpec::Integer(None)),
]);
df.validate(&spec)?;Sourcepub fn into_named_list(self) -> NamedList
pub fn into_named_list(self) -> NamedList
Convert to the underlying NamedList, consuming the data frame wrapper.
The SEXP retains its data.frame class attribute.
Trait Implementations§
Source§impl Debug for DataFrameView
impl Debug for DataFrameView
Source§impl IntoR for DataFrameView
impl IntoR for DataFrameView
Source§type Error = Infallible
type Error = Infallible
Source§fn try_into_sexp(self) -> Result<SEXP, Self::Error>
fn try_into_sexp(self) -> Result<SEXP, Self::Error>
Source§impl TryFromSexp for DataFrameView
impl TryFromSexp for DataFrameView
Auto Trait Implementations§
impl Freeze for DataFrameView
impl RefUnwindSafe for DataFrameView
impl Send for DataFrameView
impl Sync for DataFrameView
impl Unpin for DataFrameView
impl UnsafeUnpin for DataFrameView
impl UnwindSafe for DataFrameView
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> SizeEq<MaybeUninit<T>> for T
impl<T> SizeEq<MaybeUninit<T>> for T
type CastFrom = CastSizedExact
Source§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read moreimpl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> InvariantsEq<ManuallyDrop<T>> for Twhere
T: ?Sized,
impl<T> InvariantsEq<T> for Twhere
T: ?Sized,
impl<T> InvariantsEq<Unalign<T>> for T
impl<T> InvariantsEq<Wrapping<T>> for T
impl<Src, Dst, A, SV, DV, R> MutationCompatible<Src, A, SV, DV, (BecauseRead, R)> for Dst
impl<Src, Dst, A, SV, DV> MutationCompatible<Src, A, SV, DV, BecauseInvariantsEq> for Dstwhere
A: Aliasing,
SV: Validity,
DV: Validity,
Src: TransmuteFrom<Dst, DV, SV> + ?Sized,
Dst: TransmuteFrom<Src, SV, DV> + InvariantsEq<Src> + ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<Cell<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<ManuallyDrop<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<ReadOnly<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<Src, Dst> TransmuteFrom<Src, Initialized, Initialized> for Dst
impl<Src, Dst, V> TransmuteFrom<Src, V, Uninit> for Dst
impl<Src, Dst> TransmuteFrom<Src, Valid, Initialized> for Dst
impl<T> TransmuteFrom<Unalign<T>, Valid, Valid> for T
impl<T> TransmuteFrom<UnsafeCell<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<Wrapping<T>, Valid, Valid> for T
impl<Src, Dst, A, SV, DV, C, R> TransmuteFromPtr<Src, A, SV, DV, C, R> for Dstwhere
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,
impl<Src, Dst, SV, DV, A, C, R> TryTransmuteFromPtr<Src, A, SV, DV, C, (BecauseMutationCompatible, R)> for Dstwhere
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: 64 bytes