Skip to main content

DataFrameRow

Derive Macro DataFrameRow 

Source
#[derive(DataFrameRow)]
{
    // Attributes available to this derive:
    #[dataframe]
}
Expand description

Derive DataFrameRow: generates a companion *DataFrame type with collection fields, plus IntoR / TryFromSexp / IntoDataFrame impls for seamless R data.frame conversion.

§Example

#[derive(DataFrameRow)]
struct Measurement {
    time: f64,
    value: f64,
}

// Generates MeasurementDataFrame { time: Vec<f64>, value: Vec<f64> }
// plus conversion impls

§Struct-level attributes

  • #[dataframe(name = "CustomDf")] — custom name for the generated DataFrame type
  • #[dataframe(align)] — pad shorter columns with NA to match longest
  • #[dataframe(tag = "my_tag")] — attach a tag attribute to the data.frame
  • #[dataframe(conflicts = "string")] — resolve conflicting column types as strings

§Field-level attributes

  • #[dataframe(skip)] — omit this field from the DataFrame
  • #[dataframe(rename = "col")] — custom column name
  • #[dataframe(as_list)] — keep collection as single list column (no expansion)
  • #[dataframe(expand)] / #[dataframe(unnest)] — expand collection into suffixed columns
  • #[dataframe(width = N)] — pin expansion width (shorter rows get NA)

§Public surface (which verbs to call)

Every capability the derive provides has a documented, trait-based (or std) verb — reach for these, not any incidental inherent plumbing:

  • Rows → R data.frame: rows.into_dataframe()? (owned, GC-rooted BuiltDataFrame) or rows.wrap_data_frame() (deferred IntoR wrapper); parallel variant rows.into_dataframe_par()?. From the IntoDataFrame / AsDataFrameExt traits (both re-exported from miniextendr_api::prelude).
  • R data.frame → rows: Vec::<Row>::from_dataframe(&df)? (parallel: Vec::<Row>::from_dataframe_par(&df)?), from the FromDataFrame trait — or the one-call Row::try_from_dataframe(sexp) reader on the row type.
  • Rows ↔ the pure-Rust columnar companion (<Row>DataFrame, Vec-columns, no R involved): the ColumnarFrame trait (in the prelude) — <Row>DataFrame::from_rows(rows) / from_rows_par(rows) (parallel build of the companion, which into_dataframe_par does not give you) and, for row-iterable companions, companion.into_rows(). Vec<Row>: Into<companion> and the companion’s IntoIterator are the equivalent std verbs.
  • Enum split representation: rows.into_dataframe_split() returns one data.frame per variant as an R list (only that variant’s columns — no NA fill), from the IntoDataFrameSplit trait (in the prelude). Enum rows only; struct derives don’t partition.

The generated <Row>DataFrame / <Row>DataFrameIter types are intermediate column-oriented companions; you rarely name them directly.