Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

10_object_arrays_and_main_subclasses

Object Arrays and Main Subclasses


Description

One, two and higher-dimensional object arrays, along with their main subclasses.

Usage

ObjectArray (CLASS="<OBJECT>", n, ..., names, default.value=NULL)
NestMatrix (nr, nc, ..., rnames, cnames, conform=TRUE, recursive=FALSE,
    default.value=ZERO)
MatrixArray (n, ..., conform=TRUE, default.value=ZERO)

as.ObjectArray (x, CLASS="<OBJECT>", n, ..., names)
as.NestMatrix (x, ..., rnames, cnames, conform=TRUE, recursive=FALSE)

Arguments

CLASS

A character vector of classes.
Every object in the object array, needs to be of these classes.
Note that the order is not important.

The default, "<OBJECT>", means that objects can be of any class.

n

Integer, the dimensions.

nr, nc

Integers, the dimensions, same as n, where n is of length two.

names

List of character vectors, of names in each dimension, which should match n, above.
May be NULL or contain NULL values.

rnames, cnames

Character vectors of nr row names and nc column names.
May be NULL.
Currently ignored, when a NestMatrix is constructed from a PartMatrix.

conform

Logical, if true, submatrices are required to have conformable dimensions.
Note that a NestMatrix may contain ZERO(s) regardless of the whether there's a conformable requirement or not.

recursive

Logical, if true, sub elements can be nested matrices.
Otherwise, they must be standard matrices or ZERO.

default.value

Default value, for each element.
In NestMatrix, the defaul value is ZERO.

x

In as.ObjectArray, a list.
In as.NestMatrix, a matrix or a PartMatrix.

...

Ignored.

Details

ObjectArray(s) are similar to list matrices and list arrays.
(But these are S4 classes, with a number of differences).

Setting individual elements to NULL, doesn't remove them.
And they support formatting, via objtag methods.

By default, and ObjectArray can contain any objects, however, this can be restricted by the CLASS argument.

A NestMatrix is a subclass of an ObjectArray that contains ZERO or standard matrices.
If recursive is true, then it may also contain other NestMatrix objects.

Note that NestMatrix elements can have a scalar value assigned, but it will be converted to a 1x1 matrix.

A MatrixArray is also a subclass of an ObjectArray, with contains standard matrices.
And is designed for matrix array multiplication.

ZERO is an instance of the class ZERO.
This is a generalization of zero matrices.
Which can be used in NestMatrix objects, without being constrained by conformable dimensions.

Note, do not to access slots directly.
(But rather use functions within this package).

Value

All functions return objects of their classes.

See Also

VMap
Another subclass of ObjectArray.

PartMatrix
Similar to NestMatrix.

SectMatrix
A generalization of PartMatrix

Binary Operators
Operations on MatrixArray objects.

Examples

v <- ObjectArray ("list", c (2, 2) )
v [[1, 1]] <- list (1)
v [[2, 1]] <- list (1, 2)
v [[1, 2]] <- list (1, 2, 3)
v [[2, 2]] <- list (1, 2, 3, 4)
v

v [[1, 2]]

nm1 <- NestMatrix (4, 4)
nm1

msub <- NestMatrix (4, 4)
nm2 <- NestMatrix (4, 4, recursive=TRUE, default.value=msub)
nm2

nm3 <- as.NestMatrix (PartMatrix (5, 5, 2:4, 2:4) )
nm3

vectools

Advanced Vector Toolkit

v0.2.0
GPL (>= 2)
Authors
Abby Spurdle
Initial release
2020-10-22

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.