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.