pub struct ToDataFrame<T: IntoDataFrame>(pub T);Expand description
Wrap a value and convert it to an R data.frame via IntoDataFrame when returned from Rust.
Use this wrapper when you want to convert a single value to an R data.frame without making that the default behavior for the type.
§Example
ⓘ
struct TimeSeries {
timestamps: Vec<f64>,
values: Vec<f64>,
}
impl IntoDataFrame for TimeSeries {
fn into_data_frame(self) -> List {
List::from_pairs(vec![
("timestamp", self.timestamps),
("value", self.values),
])
.set_class_str(&["data.frame"])
.set_row_names_int(self.timestamps.len())
}
}
#[miniextendr]
fn make_time_series() -> ToDataFrame<TimeSeries> {
ToDataFrame(TimeSeries {
timestamps: vec![1.0, 2.0, 3.0],
values: vec![10.0, 20.0, 30.0],
})
}
// In R: make_time_series() returns a data.frameTuple Fields§
§0: TTrait Implementations§
Source§impl<T: Clone + IntoDataFrame> Clone for ToDataFrame<T>
impl<T: Clone + IntoDataFrame> Clone for ToDataFrame<T>
Source§fn clone(&self) -> ToDataFrame<T>
fn clone(&self) -> ToDataFrame<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug + IntoDataFrame> Debug for ToDataFrame<T>
impl<T: Debug + IntoDataFrame> Debug for ToDataFrame<T>
Source§impl<T: IntoDataFrame> From<T> for ToDataFrame<T>
impl<T: IntoDataFrame> From<T> for ToDataFrame<T>
Source§impl<T: IntoDataFrame> IntoR for ToDataFrame<T>
impl<T: IntoDataFrame> IntoR for ToDataFrame<T>
Source§type Error = Infallible
type Error = Infallible
The error type for fallible conversions. Read more
Source§fn try_into_sexp(self) -> Result<SEXP, Self::Error>
fn try_into_sexp(self) -> Result<SEXP, Self::Error>
Try to convert this value to an R SEXP. Read more
impl<T: Copy + IntoDataFrame> Copy for ToDataFrame<T>
Auto Trait Implementations§
impl<T> Freeze for ToDataFrame<T>where
T: Freeze,
impl<T> RefUnwindSafe for ToDataFrame<T>where
T: RefUnwindSafe,
impl<T> Send for ToDataFrame<T>where
T: Send,
impl<T> Sync for ToDataFrame<T>where
T: Sync,
impl<T> Unpin for ToDataFrame<T>where
T: Unpin,
impl<T> UnsafeUnpin for ToDataFrame<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for ToDataFrame<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more