pub struct Pairlist {
    pub(crate) robj: Robj,
}

Fields§

§robj: Robj

Implementations§

source§

impl Pairlist

source

pub fn new() -> Self

source

pub fn from_pairs<NV>(pairs: NV) -> Self

Convert an iterator of names and values to a pairlist object.

use extendr_api::prelude::*;
test! {
    let pairs = (0..100).map(|i| (format!("n{}", i), i));
    let pairlist = Pairlist::from_pairs(pairs);
    assert_eq!(pairlist.len(), 100);

    // Use "" to indicate the absense of the name
    let unnamed_pairlist = Pairlist::from_pairs([("", "a"), ("", "b")]);
    assert_eq!(call!("names", unnamed_pairlist)?, r!(NULL));
    let unnamed_pairlist_r = R!(r#"pairlist("a", "b")"#)?.as_pairlist().unwrap();
    assert_eq!(unnamed_pairlist_r.names().collect::<Vec<_>>(), vec!["", ""]);
}
source

pub fn iter(&self) -> PairlistIter

Generate paits of names and values.

use extendr_api::prelude::*;
test! {
    let pairs = (0..100).map(|i| (format!("n{}", i), i));
    let pairlist = Pairlist::from_pairs(pairs);
    assert_eq!(pairlist.iter().count(), 100);
    assert_eq!(pairlist.iter().nth(50), Some(("n50", r!(50))));
}
source

pub fn names(&self) -> impl Iterator<Item = &'static str>

source

pub fn values(&self) -> impl Iterator<Item = Robj>

Trait Implementations§

source§

impl Clone for Pairlist

source§

fn clone(&self) -> Pairlist

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 Conversions for Pairlist

as_*()

source§

fn as_symbol(&self) -> Option<Symbol>

Convert a symbol object to a Symbol wrapper. Read more
source§

fn as_char(&self) -> Option<Rstr>

Convert a CHARSXP object to a Rstr wrapper. Read more
source§

fn as_raw(&self) -> Option<Raw>

Convert a raw object to a Rstr wrapper. Read more
source§

fn as_language(&self) -> Option<Language>

Convert a language object to a Language wrapper. Read more
source§

fn as_pairlist(&self) -> Option<Pairlist>

Convert a pair list object (LISTSXP) to a Pairlist wrapper. Read more
source§

fn as_list(&self) -> Option<List>

Convert a list object (VECSXP) to a List wrapper. Read more
source§

fn as_expressions(&self) -> Option<Expressions>

Convert an expression object (EXPRSXP) to a Expr wrapper. Read more
source§

fn as_environment(&self) -> Option<Environment>

Convert an environment object (ENVSXP) to a Env wrapper. Read more
source§

fn as_function(&self) -> Option<Function>

Convert a function object (CLOSXP) to a Function wrapper. Read more
source§

fn as_promise(&self) -> Option<Promise>

Get a wrapper for a promise.
source§

impl Debug for Pairlist

source§

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

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

impl Default for Pairlist

source§

fn default() -> Self

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

impl From<&Pairlist> for Robj

source§

fn from(val: &Pairlist) -> Self

Make an robj from a wrapper.

source§

impl From<()> for Pairlist

source§

fn from(_: ()) -> Self

Construct a NULL pairlist (which is a NULL).

source§

impl From<Pairlist> for Robj

source§

fn from(val: Pairlist) -> Self

Make an robj from a wrapper.

source§

impl<'a> FromRobj<'a> for Pairlist

source§

fn from_robj(robj: &'a Robj) -> Result<Self, &'static str>

source§

impl GetSexp for Pairlist

source§

unsafe fn get(&self) -> SEXP

Get a copy of the underlying SEXP. Read more
source§

unsafe fn get_mut(&mut self) -> SEXP

source§

fn as_robj(&self) -> &Robj

Get a reference to a Robj for this type.
source§

fn as_robj_mut(&mut self) -> &mut Robj

Get a mutable reference to a Robj for this type.
source§

impl IntoIterator for Pairlist

source§

fn into_iter(self) -> Self::IntoIter

Convert a PairList into an interator, consuming the pairlist.

use extendr_api::prelude::*;
test! {
    let pairlist = pairlist!(a=1, 2).as_pairlist().unwrap();
    let vec : Vec<_> = pairlist.into_iter().collect();
    assert_eq!(vec, vec![("a", r!(1)), ("", r!(2))]);
}
§

type IntoIter = PairlistIter

Which kind of iterator are we turning this into?
§

type Item = (&'static str, Robj)

The type of the elements being iterated over.
source§

impl Length for Pairlist

len() and is_empty()

source§

fn len(&self) -> usize

Get the extended length of the object. Read more
source§

fn is_empty(&self) -> bool

Returns true if the Robj contains no elements. Read more
source§

impl Operators for Pairlist

dollar() etc.

source§

fn dollar<T>(&self, symbol: T) -> Result<Robj>
where T: AsRef<str>,

Do the equivalent of x$y Read more
source§

fn slice<T>(&self, rhs: T) -> Result<Robj>
where T: Into<Robj>,

Do the equivalent of x[y] Read more
source§

fn index<T>(&self, rhs: T) -> Result<Robj>
where T: Into<Robj>,

Do the equivalent of x[[y]] Read more
source§

fn tilde<T>(&self, rhs: T) -> Result<Robj>
where T: Into<Robj>,

Do the equivalent of x ~ y Read more
source§

fn double_colon<T>(&self, rhs: T) -> Result<Robj>
where T: Into<Robj>,

Do the equivalent of x :: y Read more
source§

fn call(&self, args: Pairlist) -> Result<Robj>

Do the equivalent of x(a, b, c) Read more
source§

impl PartialEq for Pairlist

source§

fn eq(&self, other: &Pairlist) -> bool

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

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Rinternals for Pairlist

find_var() etc.

source§

fn is_null(&self) -> bool

Return true if this is the null object.
source§

fn is_symbol(&self) -> bool

Return true if this is a symbol.
source§

fn is_logical(&self) -> bool

Return true if this is a boolean (logical) vector
source§

fn is_real(&self) -> bool

Return true if this is a real (f64) vector.
source§

fn is_complex(&self) -> bool

Return true if this is a complex vector.
source§

fn is_expressions(&self) -> bool

Return true if this is an expression.
source§

fn is_environment(&self) -> bool

Return true if this is an environment.
source§

fn is_promise(&self) -> bool

Return true if this is an environment.
source§

fn is_string(&self) -> bool

Return true if this is a string.
source§

fn is_object(&self) -> bool

Return true if this is an object (ie. has a class attribute).
source§

fn is_s4(&self) -> bool

Return true if this is a S4 object.
source§

fn is_external_pointer(&self) -> bool

Return true if this is an expression.
source§

fn get_current_srcref(val: i32) -> Robj

Get the source ref.
source§

fn get_src_filename(&self) -> Robj

Get the source filename.
source§

fn as_character_vector(&self) -> Robj

Convert to a string vector.
source§

fn coerce_vector(&self, sexptype: u32) -> Robj

Convert to vectors of many kinds.
source§

fn pair_to_vector_list(&self) -> Robj

Convert a pairlist (LISTSXP) to a vector list (VECSXP).
source§

fn vector_to_pair_list(&self) -> Robj

Convert a vector list (VECSXP) to a pair list (LISTSXP)
source§

fn as_character_factor(&self) -> Robj

Convert a factor to a string vector.
source§

fn alloc_matrix(sexptype: SEXPTYPE, rows: i32, cols: i32) -> Robj

Allocate a matrix object.
source§

fn duplicate(&self) -> Robj

Do a deep copy of this object. Note that clone() only adds a reference.
source§

fn find_function<K: TryInto<Symbol, Error = Error>>( &self, key: K ) -> Result<Robj>

Find a function in an environment ignoring other variables. Read more
source§

fn find_var<K: TryInto<Symbol, Error = Error>>(&self, key: K) -> Result<Robj>

Find a variable in an environment. Read more
source§

fn eval_promise(&self) -> Result<Robj>

If this object is a promise, evaluate it, otherwise return the object. Read more
source§

fn ncols(&self) -> usize

Number of columns of a matrix
source§

fn nrows(&self) -> usize

Number of rows of a matrix
source§

fn xlengthgets(&self, new_len: usize) -> Result<Robj>

source§

fn alloc_vector(sexptype: u32, len: usize) -> Robj

Allocated an owned object of a certain type.
source§

fn conformable(a: &Robj, b: &Robj) -> bool

Return true if two arrays have identical dims.
source§

fn is_array(&self) -> bool

Return true if this is an array.
source§

fn is_factor(&self) -> bool

Return true if this is factor.
source§

fn is_frame(&self) -> bool

Return true if this is a data frame.
source§

fn is_function(&self) -> bool

Return true if this is a function or a primitive (CLOSXP, BUILTINSXP or SPECIALSXP)
source§

fn is_integer(&self) -> bool

Return true if this is an integer vector (INTSXP) but not a factor.
source§

fn is_language(&self) -> bool

Return true if this is a language object (LANGSXP).
source§

fn is_pairlist(&self) -> bool

Return true if this is NILSXP or LISTSXP.
source§

fn is_matrix(&self) -> bool

Return true if this is a matrix.
source§

fn is_list(&self) -> bool

Return true if this is NILSXP or VECSXP.
source§

fn is_number(&self) -> bool

Return true if this is INTSXP, LGLSXP or REALSXP but not a factor.
source§

fn is_primitive(&self) -> bool

Return true if this is a primitive function BUILTINSXP, SPECIALSXP.
source§

fn is_ts(&self) -> bool

Return true if this is a time series vector (see tsp).
source§

fn is_user_binop(&self) -> bool

Return true if this is a user defined binop.
source§

fn is_valid_string(&self) -> bool

Return true if this is a valid string.
source§

fn is_valid_string_f(&self) -> bool

Return true if this is a valid string.
source§

fn is_vector(&self) -> bool

Return true if this is a vector.
source§

fn is_vector_atomic(&self) -> bool

Return true if this is an atomic vector.
source§

fn is_vector_list(&self) -> bool

Return true if this is a vector list.
source§

fn is_vectorizable(&self) -> bool

Return true if this is can be made into a vector.
source§

fn is_raw(&self) -> bool

Return true if this is RAWSXP.
source§

fn is_char(&self) -> bool

Return true if this is CHARSXP.
source§

fn is_missing_arg(&self) -> bool

source§

fn is_unbound_value(&self) -> bool

source§

fn is_package_env(&self) -> bool

source§

fn package_env_name(&self) -> Robj

source§

fn is_namespace_env(&self) -> bool

source§

fn namespace_env_spec(&self) -> Robj

source§

fn is_altrep(&self) -> bool

Returns true if this is an ALTREP object.
source§

fn is_altinteger(&self) -> bool

Returns true if this is an integer ALTREP object.
source§

fn is_altreal(&self) -> bool

Returns true if this is an real ALTREP object.
source§

fn is_altlogical(&self) -> bool

Returns true if this is an logical ALTREP object.
source§

fn is_altraw(&self) -> bool

Returns true if this is a raw ALTREP object.
source§

fn is_altstring(&self) -> bool

Returns true if this is an integer ALTREP object.
source§

fn is_altlist(&self) -> bool

Returns true if this is an integer ALTREP object.
source§

fn deparse(&self) -> Result<String>

Generate a text representation of this object.
source§

impl Serialize for Pairlist

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Slices for Pairlist

as_typed_slice_raw() etc.

source§

unsafe fn as_typed_slice_raw<T>(&self) -> &[T]

Get an immutable slice to this object’s data. Read more
source§

unsafe fn as_typed_slice_raw_mut<T>(&mut self) -> &mut [T]

Get a mutable slice to this object’s data. Read more
source§

impl TryFrom<&Robj> for Pairlist

source§

fn try_from(robj: &Robj) -> Result<Self>

Make a wrapper from a robj if it matches.

§

type Error = Error

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

impl TryFrom<Robj> for Pairlist

source§

fn try_from(robj: Robj) -> Result<Self>

Make a wrapper from a robj if it matches.

§

type Error = Error

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

impl Types for Pairlist

rtype() and rany()

source§

fn rtype(&self) -> Rtype

Get the type of an R object. Read more
source§

fn as_any(&self) -> Rany<'_>

source§

impl StructuralPartialEq for Pairlist

Auto Trait Implementations§

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> 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> 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> IntoRobj for T
where Robj: From<T>,

source§

impl<R> Save for R
where R: GetSexp,

source§

fn save<P: AsRef<Path>>( &self, path: &P, format: PstreamFormat, version: i32, hook: Option<WriteHook> ) -> Result<()>

Save an object in the R data format. version should probably be 3.
source§

fn to_writer<W: Write>( &self, writer: &mut W, format: PstreamFormat, version: i32, hook: Option<WriteHook> ) -> Result<()>

Save an object in the R data format to a Write trait. version should probably be 3.
source§

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

§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.