garray: Generalized and smart array

Description Usage Arguments Details Functions Examples

Description

Creates or tests for generalized arrays.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
garray(data, dim = NULL, dimnames = NULL, margins = NULL,
  sdim = attr(data, "sdim", exact = TRUE))

garray.array(x, sdim)

as.garray(x, ...)

## S3 method for class 'garray'
as.garray(x, ...)

## Default S3 method:
as.garray(x, ...)

is.garray(x)

is.garray.duck(x)

is.scalar(x)

Arguments

data

Usually a simple array, and can be a vector without dimensions.

dim

An integer vector giving the maximal indices in each dimension.

dimnames

A list (or it will be ignored) with for each dimension one component, either ‘NULL’ or a character vector.

margins

Override the names of dim and of dimnames.

sdim

Optional, a named list of numeric vectors indicating the subdivision of some of the dimensions. The value vill become, after validated, the attribute sdim. See 'Details' and '?sdim'.

x

An R object.

...

Additional arguments to be passed to or from methods.

Details

Generalized arrays are generalized because they handle dimensions and subdimensions that are ragged; and they are also smart because they automatically match dimensions by margins (names of dimnames). Margins is implemented similar to R's native class "table", i.e., use names of dimnames to store the margins

Attribute sdim denotes subdimensions, which are the subdivision of dimensions or grouping of members of a dimension, for organizing a ragged array. It is a named list of numeric vectors, each of which indicates the lengths of subdivision groups within a dimension. Every name of the list prefixed with a margin of the generalized array. By the matching of sdim names and dim names, utility functions figure out which dimensions the sub dimensions reside in. Sum of a vector of the list usually equals to the extent of the corresponding dimension. If they are not equal and the extent can not be divided exactly by the sum, the subdimension is invalid and will be dropped. If the extent can be divided exactly by the sum, the subdimension is still valid but non-canonical. Non-canonical subdimension can be provided to garray() and sdim<- as argument, and the two functions canonicalize it. Other utility functions cannot handle non-canonical subdimension, thus manually constructing objects of garray class is permitted but dangerous. Values of each vector of the list denotes the repeating times of subdimension residing in the coresponding dimension (called superdim). More than 1 subdimension reside in the same superdim is allowed. This feature allows dividing a subdimension further, organizing the subdims into hierachy.

By definition and for S3 dispatching, class(.)="garray" is required, but simple arrays with proper margins actually work correctly with most functionalities of this package. For the sake of compatibility and reducing warning message, is.garray.duck() tests whether the array has proper margins.

A still problem is that attributes in R are fragile, even indexing will drop most attributes. Utility functions and methods for dispatching for 'garray' implemented in this package guaranttee to save the margins (names of dimnames) and subdimension (attr(*,'sdim')).

Functions

Examples

1
2
a1 <- garray(1:27, c(A=3,B=9), sdim=list(AA=c(a=2,b=1),BB=c(a=3)))
a2 <- garray(1:27, c(A=3,B=9), sdim=list(AA=c(a=2,b=1),BB=c(a=4)))

garray documentation built on May 1, 2019, 8:47 p.m.