Type Alias RColumn

Source
pub type RColumn<T> = RArray<T, 1>;

Aliased Type§

struct RColumn<T> {
    robj: Robj,
    _data: PhantomData<T>,
}

Fields§

§robj: Robj

Owning Robj (probably should be a Pin).

§_data: PhantomData<T>

Data type of the n-array

Implementations§

Source§

impl<T> RColumn<T>
where T: ToVectorValue, Robj: for<'a> AsTypedSlice<'a, T>,

Source

pub fn new_column<F: FnMut(usize) -> T>(nrows: usize, f: F) -> Self

Make a new column type.

Source

pub fn nrows(&self) -> usize

Get the number of rows.

Source§

impl<T, const NDIM: usize> RArray<T, NDIM>
where Robj: for<'a> AsTypedSlice<'a, T>,

Source

pub fn from_parts(robj: Robj) -> Self

Source

pub fn data(&self) -> &[T]

Returns a flat representation of the array in col-major.

Source

pub fn data_mut(&mut self) -> &mut [T]

Returns a flat, mutable representation of the array in col-major.

Source

pub fn ndim(&self) -> usize

Returns the number of dimensions.

Source

pub fn dim(&self) -> Vec<usize>

Returns the dimensions of the array.

Source§

impl<T, const NDIM: usize> RArray<T, NDIM>

Source

pub fn get_dimnames(&self) -> List

Source

pub fn get_dim(&self) -> Vec<usize>

Get the dimension vector of the array.

Equivalent to dim() in R

Source

pub fn set_names(&mut self, names: Strings)

Set the names of the elements of an array.

Equivalent to names<- in R

Source

pub fn set_dimnames(&mut self, dimnames: List)

Set the dimension names of an array.

For RMatrix a list of length 2 is required, as that would entail column-names and row-names. If you only wish to set one, but not the other, then the unset element must be R NULL

Equivalent to dimnames<- in R

Source

pub fn set_dim(&mut self, dim: Robj)

Set the dimensions of an array.

Equivalent to dim<-

Source§

impl<T, const NDIM: usize> RArray<T, NDIM>
where T: ToVectorValue, Robj: for<'a> AsTypedSlice<'a, T>,

Source

pub fn new_array(dim: [usize; NDIM]) -> Self

Trait Implementations§

Source§

impl<T> TryFrom<&Robj> for RColumn<T>
where Robj: for<'a> AsTypedSlice<'a, T>,

Source§

type Error = Error

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

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

Performs the conversion.
Source§

impl<T> TryFrom<Robj> for RColumn<T>
where Robj: for<'a> AsTypedSlice<'a, T>,

Source§

type Error = Error

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

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

Performs the conversion.
Source§

impl<T: Debug, const NDIM: usize> Debug for RArray<T, NDIM>

Source§

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

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

impl<T, const NDIM: usize> Deref for RArray<T, NDIM>

Source§

type Target = Robj

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T, const NDIM: usize> DerefMut for RArray<T, NDIM>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T, const NDIM: usize> Index<[usize; NDIM]> for RArray<T, NDIM>
where Robj: for<'a> AsTypedSlice<'a, T>,

Source§

fn index(&self, index: [usize; NDIM]) -> &Self::Output

Zero-based indexing for DIM-dimensional arrays.

Panics if out of bounds. Zero-based indexing in row, column order.

Panics if out of bounds.

use extendr_api::prelude::*;
test! {
    let matrix = RArray::new_matrix(3, 2, |r, c| [
        [1., 2., 3.],
        [4., 5., 6.]][c][r]);
    assert_eq!(matrix[[0, 0]], 1.);
    assert_eq!(matrix[[1, 0]], 2.);
    assert_eq!(matrix[[2, 1]], 6.);

    let matrix = RArray::new_matrix3d(3, 2, 2, |r, c, d| (r + c + d) as f64);
    assert_eq!(matrix[[0, 0, 0]], 0.);
    assert_eq!(matrix[[1, 0, 1]], 2.);
    assert_eq!(matrix[[2, 1, 1]], 4.);
}
Source§

type Output = T

The returned type after indexing.
Source§

impl<T, const NDIM: usize> IndexMut<[usize; NDIM]> for RArray<T, NDIM>
where Robj: for<'a> AsTypedSlice<'a, T>,

Source§

fn index_mut(&mut self, index: [usize; NDIM]) -> &mut Self::Output

Zero-based mutable indexing for DIM-dimensional arrays.

Panics if out of bounds.

use extendr_api::prelude::*;
test! {
    let mut matrix = RMatrix::new_matrix(3, 2, |_, _| 0.);
    matrix[[0, 0]] = 1.;
    matrix[[1, 0]] = 2.;
    matrix[[2, 0]] = 3.;
    matrix[[0, 1]] = 4.;
    assert_eq!(matrix.as_real_slice().unwrap(), &[1., 2., 3., 4., 0., 0.]);

   let mut matrix = RMatrix3D::new_matrix3d(3, 2, 2, |_, _, _| 0.);
   matrix[[0, 0, 0]] = 1.;
   matrix[[1, 0, 0]] = 2.;
   matrix[[2, 0, 0]] = 3.;
   matrix[[0, 1, 0]] = 4.;
   assert_eq!(matrix.as_real_slice().unwrap(),
       &[1., 2., 3., 4., 0., 0., 0., 0., 0., 0., 0., 0.]);
}
Source§

impl<T, const NDIM: usize> Offset<[usize; NDIM]> for RArray<T, NDIM>

Source§

fn offset(&self, index: [usize; NDIM]) -> usize

Get the offset into the array for a given index.

Source§

impl<T: PartialEq, const NDIM: usize> PartialEq for RArray<T, NDIM>

Source§

fn eq(&self, other: &RArray<T, NDIM>) -> 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<T, const NDIM: usize> StructuralPartialEq for RArray<T, NDIM>