Enum r::object::rep::Rep

source ·
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>

source

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]].

source

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>

source

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))
source

pub fn is_named(&self) -> bool

Whether the vector representation has names.

source

pub fn names(&self) -> Option<CowObj<Vec<Character>>>

Return the names of the vector if there are any.

source

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.

source

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.

source

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.

source

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.

source

pub fn iter_pairs(&self) -> IterablePairs<T>

Iterate over (owned) pairs of names and values ((String, T)).

source

pub fn iter_values(&self) -> IterableValues<T>

Iterate over the (owned) values of the vector.

source

pub fn iter_names(&self) -> Option<IterableValues<Character>>

Iterate over the names of the vector (if they exist).

source

pub fn push_value(&mut self, value: T)

source

pub fn push_named(&mut self, name: OptionNA<String>, value: T)

Push a named value with a given name onto the Rep<T>.

source

pub fn iter_subset_indices_exact(&self) -> ExactIterSubsetIndices

source

pub fn iter_subset_indices(&self) -> Box<dyn Iterator<Item = Option<usize>>>

source

pub fn reindex(&mut self)

Reindex the mapping from names to indices.

source

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.

source

pub fn dedup_last(self) -> Self

source

pub fn set_names(&self, names: CowObj<Vec<Character>>) -> Self

source

pub fn inner(&self) -> CowObj<Vec<T>>

Access a lazy copy of the internal vector data

source

pub fn with_inner_mut<F, R>(&self, f: F) -> R
where F: FnOnce(&mut Vec<T>) -> R,

Get mutable access to the internal vector through the passed closure.

source

pub fn subset(&self, subset: Subset) -> Self

Subsetting a Vector

Introduce a new subset into the aggregate list of subset indices.

source

pub fn len(&self) -> usize

The length of the vector.

source

pub fn is_empty(&self) -> bool

Whether the vector has length 0.

source

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

source

pub fn assign<R>(&mut self, value: Rep<R>) -> Result<Self, Signal>
where T: Clone + Default + From<R>, R: Default + Clone,

Assignment to Subset Indices

Assignment to a vector from another. The aggregate subsetted indices are iterated over while performing the assignment.

source

pub fn as_scalar(&self) -> Option<T>

Return the only value if the vector has length 1.

source

pub fn materialize(&self) -> Self
where T: Clone,

Materialize a Vector

Apply subsets and clone values into a new vector.

source

pub fn is_double(&self) -> bool
where 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.

source

pub fn is_logical(&self) -> bool
where T: AtomicMode,

See Self::is_double for more information

source

pub fn is_integer(&self) -> bool
where T: AtomicMode,

See Self::is_double for more information

source

pub fn is_character(&self) -> bool
where T: AtomicMode,

See Self::is_double for more information

source

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)
]))
source

pub fn as_logical(&self) -> Rep<Logical>

See Self::as_mode for more information

source

pub fn as_integer(&self) -> Rep<Integer>

See Self::as_mode for more information

source

pub fn as_double(&self) -> Rep<Double>

See Self::as_mode for more information

source

pub fn as_character(&self) -> Rep<Character>

See Self::as_mode for more information

source

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,

source§

type Output = Result<Rep<C>, Signal>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Rep<R>) -> Self::Output

Performs the + operation. Read more
source§

impl<L, R> BitAnd<Rep<R>> for Rep<L>

source§

type Output = Result<Rep<OptionNA<bool>>, Signal>

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: Rep<R>) -> Self::Output

Performs the & operation. Read more
source§

impl<L, R> BitOr<Rep<R>> for Rep<L>

source§

type Output = Result<Rep<OptionNA<bool>>, Signal>

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: Rep<R>) -> Self::Output

Performs the | operation. Read more
source§

impl<T: Clone> Clone for Rep<T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug + Clone> Debug for Rep<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Clone + Default> Default for Rep<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T> Display for Rep<T>
where T: AtomicMode + Debug + Default + Clone,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
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,

source§

type Output = Result<Rep<C>, Signal>

The resulting type after applying the / operator.
source§

fn div(self, rhs: Rep<R>) -> Self::Output

Performs the / operation. Read more
source§

impl<F, T> From<(Vec<F>, Subsets)> for Rep<T>
where Rep<T>: From<Vec<F>>, T: Clone,

source§

fn from(value: (Vec<F>, Subsets)) -> Self

Converts to this type from the input type.
source§

impl<T: Clone> From<CowObj<Vec<T>>> for Rep<T>

source§

fn from(value: CowObj<Vec<T>>) -> Self

Converts to this type from the input type.
source§

impl From<Rep<OptionNA<String>>> for Vector

source§

fn from(x: Rep<Character>) -> Self

Converts to this type from the input type.
source§

impl From<Rep<OptionNA<bool>>> for Vector

source§

fn from(x: Rep<Logical>) -> Self

Converts to this type from the input type.
source§

impl From<Rep<OptionNA<f64>>> for Vector

source§

fn from(x: Rep<Double>) -> Self

Converts to this type from the input type.
source§

impl From<Rep<OptionNA<i32>>> for Vector

source§

fn from(x: Rep<Integer>) -> Self

Converts to this type from the input type.
source§

impl<T: Clone> From<Vec<(Option<String>, T)>> for Rep<T>

source§

fn from(value: Vec<(Option<String>, T)>) -> Self

Converts to this type from the input type.
source§

impl<T: Clone + Default> From<Vec<(OptionNA<String>, T)>> for Rep<T>

source§

fn from(value: Vec<(Character, T)>) -> Self

Converts to this type from the input type.
source§

impl From<Vec<OptionNA<String>>> for Rep<Character>

source§

fn from(value: Vec<OptionNA<String>>) -> Self

Converts to this type from the input type.
source§

impl From<Vec<OptionNA<bool>>> for Rep<Logical>

source§

fn from(value: Vec<OptionNA<bool>>) -> Self

Converts to this type from the input type.
source§

impl From<Vec<OptionNA<f64>>> for Rep<Double>

source§

fn from(value: Vec<OptionNA<f64>>) -> Self

Converts to this type from the input type.
source§

impl From<Vec<OptionNA<i32>>> for Rep<Integer>

source§

fn from(value: Vec<OptionNA<i32>>) -> Self

Converts to this type from the input type.
source§

impl From<Vec<String>> for Rep<Character>

source§

fn from(value: Vec<String>) -> Self

Converts to this type from the input type.
source§

impl From<Vec<bool>> for Rep<Logical>

source§

fn from(value: Vec<bool>) -> Self

Converts to this type from the input type.
source§

impl From<Vec<f64>> for Rep<Double>

source§

fn from(value: Vec<f64>) -> Self

Converts to this type from the input type.
source§

impl From<Vec<i32>> for Rep<Integer>

source§

fn from(value: Vec<i32>) -> Self

Converts to this type from the input type.
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,

source§

type Output = Result<Rep<C>, Signal>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Rep<R>) -> Self::Output

Performs the * operation. Read more
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,

source§

type Output = Result<Rep<O>, Signal>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl<L> Not for Rep<L>

source§

type Output = Result<Rep<OptionNA<bool>>, Signal>

The resulting type after applying the ! operator.
source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
source§

impl<T: PartialEq + Clone> PartialEq for Rep<T>

source§

fn eq(&self, other: &Rep<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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>>,

source§

type Output = Result<Rep<O>, Signal>

source§

fn power(self, rhs: Rep<R>) -> Self::Output

raise self to the rhs power
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,

source§

type Output = Result<Rep<C>, Signal>

The resulting type after applying the % operator.
source§

fn rem(self, rhs: Rep<R>) -> Self::Output

Performs the % operation. Read more
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,

source§

type Output = Result<Rep<C>, Signal>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Rep<R>) -> Self::Output

Performs the - operation. Read more
source§

impl TryInto<Rep<Obj>> for Obj

source§

type Error = Signal

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<List, Self::Error>

Performs the conversion.
source§

impl<T> TryInto<bool> for Rep<OptionNA<T>>

source§

type Error = ()

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<bool, Self::Error>

Performs the conversion.
source§

impl<L, R, C> VecPartialCmp<Rep<R>> for Rep<L>

source§

type Output = Result<Rep<OptionNA<bool>>, Signal>

source§

fn vec_gt(self, rhs: Rep<R>) -> Self::Output

source§

fn vec_gte(self, rhs: Rep<R>) -> Self::Output

source§

fn vec_lt(self, rhs: Rep<R>) -> Self::Output

source§

fn vec_lte(self, rhs: Rep<R>) -> Self::Output

source§

fn vec_eq(self, rhs: Rep<R>) -> Self::Output

source§

fn vec_neq(self, rhs: Rep<R>) -> Self::Output

source§

impl<T: Clone> ViewMut for Rep<T>

source§

fn view_mut(&self) -> Self

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> AsDynCompare for T
where T: Any + DynCompare,

source§

fn as_any(&self) -> &(dyn Any + 'static)

source§

fn as_dyn_compare(&self) -> &(dyn DynCompare + 'static)

source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> DynCompare for T
where T: Any + PartialEq,

source§

fn dyn_eq(&self, other: &(dyn DynCompare + 'static)) -> bool

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T, U> SameType<T> for U

source§

fn is_same_type_as(&self, _other: &T) -> bool

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,