pub enum Rep<T: Clone> {
Subset(CowObj<Vec<T>>, Subsets, Option<Naming>),
}
Expand description
Vector
Variants§
Implementations§
source§impl<T: Clone + Default + ViewMut> Rep<T>
impl<T: Clone + Default + ViewMut> Rep<T>
sourcepub fn try_get_inner(&self, subset: Subset) -> Result<T, Signal>
pub fn try_get_inner(&self, subset: Subset) -> Result<T, Signal>
Get a cloned version of the inner value.
This is used for accessing inner values like list(1)[[1]]
.
sourcepub fn try_get_inner_mut(&self, subset: Subset) -> Result<T, Signal>
pub fn try_get_inner_mut(&self, subset: Subset) -> Result<T, Signal>
Retrieve the internal data as a mutable view.
This is important for lists for things like l$a[1:2] = c(10, 11)
source§impl<T: Clone + Default> Rep<T>
impl<T: Clone + Default> Rep<T>
sourcepub fn new() -> Self
pub fn new() -> Self
Create an empty vector
The primary use case for this function is to support testing, and there
are few expected use cases outside. It is used for creating a vector
of an explicit atomic type, likely to be tested with
SameType::is_same_type_as
.
use r::utils::*;
use r::object::Vector;
use r::object::OptionNA;
let result = Vector::from(vec![1, 2, 3]);
let expect = Vector::from(Vec::<OptionNA<i32>>::new());
assert!(result.is_same_type_as(&expect))
sourcepub fn names(&self) -> Option<CowObj<Vec<Character>>>
pub fn names(&self) -> Option<CowObj<Vec<Character>>>
Return the names of the vector if there are any.
sourcepub fn set_subset(&mut self, subset: Subset, value: T) -> Result<T, Signal>
pub fn set_subset(&mut self, subset: Subset, value: T) -> Result<T, Signal>
Change a value at the location given by subset
to the provided value
.
If the subset
does not have length 1
, an error is returned.
sourcepub fn values_ref(&self) -> IntoIterableRefValues<T>
pub fn values_ref(&self) -> IntoIterableRefValues<T>
Get an IntoIterableValues<T>
which in turn can be converted into an iterator over
references to the values (&T
).
Directly getting an iterator is not possible due to lifetime issues.
sourcepub fn names_ref(&self) -> Option<IntoIterableRefNames>
pub fn names_ref(&self) -> Option<IntoIterableRefNames>
Get an Option<IntoIterableRefNames>
which in turn can be converted into an iterator over
references to the names (&String
).
None is returned when no names exist.
Directly getting an iterator is not possible due to lifetime issues.
sourcepub fn pairs_ref(&self) -> IntoIterableRefPairs<T>
pub fn pairs_ref(&self) -> IntoIterableRefPairs<T>
Get an IntoIterablePairs<T>
which in turn can be converted into an iterator over
pairs of references ((&String, &T)
).
Directly getting an iterator is not possible due to lifetime issues.
sourcepub fn iter_pairs(&self) -> IterablePairs<T> ⓘ
pub fn iter_pairs(&self) -> IterablePairs<T> ⓘ
Iterate over (owned) pairs of names and values ((String, T)
).
sourcepub fn iter_values(&self) -> IterableValues<T> ⓘ
pub fn iter_values(&self) -> IterableValues<T> ⓘ
Iterate over the (owned) values of the vector.
sourcepub fn iter_names(&self) -> Option<IterableValues<Character>>
pub fn iter_names(&self) -> Option<IterableValues<Character>>
Iterate over the names of the vector (if they exist).
pub fn push_value(&mut self, value: T)
sourcepub fn push_named(&mut self, name: OptionNA<String>, value: T)
pub fn push_named(&mut self, name: OptionNA<String>, value: T)
Push a named value
with a given name
onto the Rep<T>
.
pub fn iter_subset_indices_exact(&self) -> ExactIterSubsetIndices ⓘ
pub fn iter_subset_indices(&self) -> Box<dyn Iterator<Item = Option<usize>>>
sourcepub fn with_capacity(capacity: usize, names: bool) -> Self
pub fn with_capacity(capacity: usize, names: bool) -> Self
Constructs a new, empty Rep<T>
with at least the specified capacity
.
Names are only include if names
is true.
pub fn dedup_last(self) -> Self
pub fn set_names(&self, names: CowObj<Vec<Character>>) -> Self
sourcepub fn with_inner_mut<F, R>(&self, f: F) -> R
pub fn with_inner_mut<F, R>(&self, f: F) -> R
Get mutable access to the internal vector through the passed closure.
sourcepub fn subset(&self, subset: Subset) -> Self
pub fn subset(&self, subset: Subset) -> Self
Subsetting a Vector
Introduce a new subset into the aggregate list of subset indices.
sourcepub fn get(&self, index: usize) -> Option<Rep<T>>where
T: Clone,
pub fn get(&self, index: usize) -> Option<Rep<T>>where
T: Clone,
Get a single element from a vector
Access a single element without materializing a new vector
sourcepub fn assign<R>(&mut self, value: Rep<R>) -> Result<Self, Signal>
pub fn assign<R>(&mut self, value: Rep<R>) -> Result<Self, Signal>
Assignment to Subset Indices
Assignment to a vector from another. The aggregate subsetted indices are iterated over while performing the assignment.
sourcepub fn materialize(&self) -> Selfwhere
T: Clone,
pub fn materialize(&self) -> Selfwhere
T: Clone,
Materialize a Vector
Apply subsets and clone values into a new vector.
sourcepub fn is_double(&self) -> boolwhere
T: AtomicMode,
pub fn is_double(&self) -> boolwhere
T: AtomicMode,
Test the mode of the internal vector type
Internally, this is defined by the crate::object::coercion::AtomicMode implementation of the vector’s element type.
sourcepub fn is_logical(&self) -> boolwhere
T: AtomicMode,
pub fn is_logical(&self) -> boolwhere
T: AtomicMode,
See Self::is_double for more information
sourcepub fn is_integer(&self) -> boolwhere
T: AtomicMode,
pub fn is_integer(&self) -> boolwhere
T: AtomicMode,
See Self::is_double for more information
sourcepub fn is_character(&self) -> boolwhere
T: AtomicMode,
pub fn is_character(&self) -> boolwhere
T: AtomicMode,
See Self::is_double for more information
sourcepub fn as_mode<Mode>(&self) -> Rep<Mode>where
T: CoercibleInto<Mode>,
Mode: Clone,
pub fn as_mode<Mode>(&self) -> Rep<Mode>where
T: CoercibleInto<Mode>,
Mode: Clone,
Convert a Vector into a vector of a specific class of internal type
The internal type only needs to satisfy
crate::object::coercion::CoercibleInto for the Mode
, and for the Mode
type to implement crate::object::coercion::AtomicMode. Generally,
this is used more directly via Self::as_logical, Self::as_integer,
Self::as_double and Self::as_character, which predefine the output
type of the mode.
use r::object::Vector;
use r::object::OptionNA;
let x = Vector::from(vec![false, true, true, false]);
let n = x.as_double();
assert_eq!(n, Vector::from(vec![
OptionNA::Some(0_f64),
OptionNA::Some(1_f64),
OptionNA::Some(1_f64),
OptionNA::Some(0_f64)
]))
sourcepub fn as_logical(&self) -> Rep<Logical>where
T: CoercibleInto<Logical>,
pub fn as_logical(&self) -> Rep<Logical>where
T: CoercibleInto<Logical>,
See Self::as_mode for more information
sourcepub fn as_integer(&self) -> Rep<Integer>where
T: CoercibleInto<Integer>,
pub fn as_integer(&self) -> Rep<Integer>where
T: CoercibleInto<Integer>,
See Self::as_mode for more information
sourcepub fn as_double(&self) -> Rep<Double>where
T: CoercibleInto<Double>,
pub fn as_double(&self) -> Rep<Double>where
T: CoercibleInto<Double>,
See Self::as_mode for more information
sourcepub fn as_character(&self) -> Rep<Character>where
T: CoercibleInto<Character>,
pub fn as_character(&self) -> Rep<Character>where
T: CoercibleInto<Character>,
See Self::as_mode for more information
pub fn get_inner(&self, index: usize) -> Option<T>
Trait Implementations§
source§impl<L, R, C, O, LNum, RNum> Add<Rep<R>> for Rep<L>where
L: AtomicMode + Default + Clone + MinimallyNumeric<As = LNum> + CoercibleInto<LNum>,
R: AtomicMode + Default + Clone + MinimallyNumeric<As = RNum> + CoercibleInto<RNum>,
(LNum, RNum): CommonNum<Common = C>,
C: Clone + Add<Output = O> + Default,
Rep<C>: From<Vec<O>>,
O: Clone + Default,
impl<L, R, C, O, LNum, RNum> Add<Rep<R>> for Rep<L>where
L: AtomicMode + Default + Clone + MinimallyNumeric<As = LNum> + CoercibleInto<LNum>,
R: AtomicMode + Default + Clone + MinimallyNumeric<As = RNum> + CoercibleInto<RNum>,
(LNum, RNum): CommonNum<Common = C>,
C: Clone + Add<Output = O> + Default,
Rep<C>: From<Vec<O>>,
O: Clone + Default,
source§impl<L, R> BitAnd<Rep<R>> for Rep<L>where
L: AtomicMode + Default + Clone + CoercibleInto<Logical>,
R: AtomicMode + Default + Clone + CoercibleInto<Logical>,
impl<L, R> BitAnd<Rep<R>> for Rep<L>where
L: AtomicMode + Default + Clone + CoercibleInto<Logical>,
R: AtomicMode + Default + Clone + CoercibleInto<Logical>,
source§impl<L, R> BitOr<Rep<R>> for Rep<L>where
L: AtomicMode + Default + Clone + CoercibleInto<Logical>,
R: AtomicMode + Default + Clone + CoercibleInto<Logical>,
impl<L, R> BitOr<Rep<R>> for Rep<L>where
L: AtomicMode + Default + Clone + CoercibleInto<Logical>,
R: AtomicMode + Default + Clone + CoercibleInto<Logical>,
source§impl<L, R, C, O, LNum, RNum> Div<Rep<R>> for Rep<L>where
L: AtomicMode + Default + Clone + MinimallyNumeric<As = LNum> + CoercibleInto<LNum>,
R: AtomicMode + Default + Clone + MinimallyNumeric<As = RNum> + CoercibleInto<RNum>,
(LNum, RNum): CommonNum<Common = C>,
C: Clone + Div<Output = O> + Default,
Rep<C>: From<Vec<O>>,
O: Clone + Default,
impl<L, R, C, O, LNum, RNum> Div<Rep<R>> for Rep<L>where
L: AtomicMode + Default + Clone + MinimallyNumeric<As = LNum> + CoercibleInto<LNum>,
R: AtomicMode + Default + Clone + MinimallyNumeric<As = RNum> + CoercibleInto<RNum>,
(LNum, RNum): CommonNum<Common = C>,
C: Clone + Div<Output = O> + Default,
Rep<C>: From<Vec<O>>,
O: Clone + Default,
source§impl<L, R, C, O, LNum, RNum> Mul<Rep<R>> for Rep<L>where
L: AtomicMode + Default + Clone + MinimallyNumeric<As = LNum> + CoercibleInto<LNum>,
R: AtomicMode + Default + Clone + MinimallyNumeric<As = RNum> + CoercibleInto<RNum>,
(LNum, RNum): CommonNum<Common = C>,
C: Clone + Mul<Output = O> + Default,
Rep<C>: From<Vec<O>>,
O: Clone + Default,
impl<L, R, C, O, LNum, RNum> Mul<Rep<R>> for Rep<L>where
L: AtomicMode + Default + Clone + MinimallyNumeric<As = LNum> + CoercibleInto<LNum>,
R: AtomicMode + Default + Clone + MinimallyNumeric<As = RNum> + CoercibleInto<RNum>,
(LNum, RNum): CommonNum<Common = C>,
C: Clone + Mul<Output = O> + Default,
Rep<C>: From<Vec<O>>,
O: Clone + Default,
source§impl<L, LNum, O> Neg for Rep<L>where
L: AtomicMode + Default + Clone + MinimallyNumeric<As = LNum> + CoercibleInto<LNum>,
LNum: Neg<Output = O>,
Rep<O>: From<Vec<O>>,
O: Clone,
impl<L, LNum, O> Neg for Rep<L>where
L: AtomicMode + Default + Clone + MinimallyNumeric<As = LNum> + CoercibleInto<LNum>,
LNum: Neg<Output = O>,
Rep<O>: From<Vec<O>>,
O: Clone,
source§impl<L, R, O, LNum, RNum> Pow<Rep<R>> for Rep<L>where
L: AtomicMode + Default + Clone + MinimallyNumeric<As = LNum> + CoercibleInto<LNum>,
R: AtomicMode + Default + Clone + MinimallyNumeric<As = RNum> + CoercibleInto<RNum>,
(LNum, RNum): CommonNum<Common = O>,
O: Pow<O, Output = O> + Default + Clone,
Rep<O>: From<Vec<O>>,
impl<L, R, O, LNum, RNum> Pow<Rep<R>> for Rep<L>where
L: AtomicMode + Default + Clone + MinimallyNumeric<As = LNum> + CoercibleInto<LNum>,
R: AtomicMode + Default + Clone + MinimallyNumeric<As = RNum> + CoercibleInto<RNum>,
(LNum, RNum): CommonNum<Common = O>,
O: Pow<O, Output = O> + Default + Clone,
Rep<O>: From<Vec<O>>,
source§impl<L, R, C, O, LNum, RNum> Rem<Rep<R>> for Rep<L>where
L: AtomicMode + Default + Clone + MinimallyNumeric<As = LNum> + CoercibleInto<LNum>,
R: AtomicMode + Default + Clone + MinimallyNumeric<As = RNum> + CoercibleInto<RNum>,
(LNum, RNum): CommonNum<Common = C>,
C: Clone + Rem<Output = O> + Default,
Rep<C>: From<Vec<O>>,
O: Clone + Default,
impl<L, R, C, O, LNum, RNum> Rem<Rep<R>> for Rep<L>where
L: AtomicMode + Default + Clone + MinimallyNumeric<As = LNum> + CoercibleInto<LNum>,
R: AtomicMode + Default + Clone + MinimallyNumeric<As = RNum> + CoercibleInto<RNum>,
(LNum, RNum): CommonNum<Common = C>,
C: Clone + Rem<Output = O> + Default,
Rep<C>: From<Vec<O>>,
O: Clone + Default,
source§impl<L, R, C, O, LNum, RNum> Sub<Rep<R>> for Rep<L>where
L: AtomicMode + Default + Clone + MinimallyNumeric<As = LNum> + CoercibleInto<LNum>,
R: AtomicMode + Default + Clone + MinimallyNumeric<As = RNum> + CoercibleInto<RNum>,
(LNum, RNum): CommonNum<Common = C>,
C: Clone + Sub<Output = O> + Default,
Rep<C>: From<Vec<O>>,
O: Clone + Default,
impl<L, R, C, O, LNum, RNum> Sub<Rep<R>> for Rep<L>where
L: AtomicMode + Default + Clone + MinimallyNumeric<As = LNum> + CoercibleInto<LNum>,
R: AtomicMode + Default + Clone + MinimallyNumeric<As = RNum> + CoercibleInto<RNum>,
(LNum, RNum): CommonNum<Common = C>,
C: Clone + Sub<Output = O> + Default,
Rep<C>: From<Vec<O>>,
O: Clone + Default,
source§impl<L, R, C> VecPartialCmp<Rep<R>> for Rep<L>where
L: AtomicMode + Default + Clone + CoercibleInto<C>,
R: AtomicMode + Default + Clone + CoercibleInto<C>,
(L, R): CommonCmp<Common = C>,
C: PartialOrd + Clone + Default,
impl<L, R, C> VecPartialCmp<Rep<R>> for Rep<L>where
L: AtomicMode + Default + Clone + CoercibleInto<C>,
R: AtomicMode + Default + Clone + CoercibleInto<C>,
(L, R): CommonCmp<Common = C>,
C: PartialOrd + Clone + Default,
type Output = Result<Rep<OptionNA<bool>>, Signal>
fn vec_gt(self, rhs: Rep<R>) -> Self::Output
fn vec_gte(self, rhs: Rep<R>) -> Self::Output
fn vec_lt(self, rhs: Rep<R>) -> Self::Output
fn vec_lte(self, rhs: Rep<R>) -> Self::Output
fn vec_eq(self, rhs: Rep<R>) -> Self::Output
fn vec_neq(self, rhs: Rep<R>) -> Self::Output
impl<T: Clone> StructuralPartialEq for Rep<T>
Auto Trait Implementations§
impl<T> Freeze for Rep<T>
impl<T> !RefUnwindSafe for Rep<T>
impl<T> !Send for Rep<T>
impl<T> !Sync for Rep<T>
impl<T> Unpin for Rep<T>
impl<T> !UnwindSafe for Rep<T>
Blanket Implementations§
source§impl<T> AsDynCompare for Twhere
T: Any + DynCompare,
impl<T> AsDynCompare for Twhere
T: Any + DynCompare,
fn as_any(&self) -> &(dyn Any + 'static)
fn as_dyn_compare(&self) -> &(dyn DynCompare + 'static)
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> DynCompare for T
impl<T> DynCompare for T
fn dyn_eq(&self, other: &(dyn DynCompare + 'static)) -> bool
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more