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, const NDIM: usize> RArray<T, NDIM>where
Robj: for<'a> AsTypedSlice<'a, T>,
impl<T, const NDIM: usize> RArray<T, NDIM>where
Robj: for<'a> AsTypedSlice<'a, T>,
Source§impl<T, const NDIM: usize> RArray<T, NDIM>
impl<T, const NDIM: usize> RArray<T, NDIM>
pub fn get_dimnames(&self) -> List
Sourcepub fn get_dim(&self) -> Vec<usize>
pub fn get_dim(&self) -> Vec<usize>
Get the dimension vector of the array.
Equivalent to dim()
in R
Sourcepub fn set_names(&mut self, names: Strings)
pub fn set_names(&mut self, names: Strings)
Set the names of the elements of an array.
Equivalent to names<-
in R
Sourcepub fn set_dimnames(&mut self, dimnames: List)
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
Trait Implementations§
Source§impl<T, const NDIM: usize> Index<[usize; NDIM]> for RArray<T, NDIM>where
Robj: for<'a> AsTypedSlice<'a, T>,
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
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§impl<T, const NDIM: usize> IndexMut<[usize; NDIM]> for RArray<T, NDIM>where
Robj: for<'a> AsTypedSlice<'a, T>,
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
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.]);
}