AbstractIncidenceArray: AbstractIncidenceArray

Description Fields Methods See Also Examples

Description

An abstract class for storing an array. It has an array of data arr, which it is responsible for storing. For arrays with particular metadata, consider extending this class. However, if the class is not truly an array, consider extending FrameData.

Fields

arr

This is the full array. For extensibility, it cannot be written to directly and must be modified through methods.

cellData

A list of metadata associated with the cells of the data.

cnames

The names of columns in the data.

colData

A list of metadata associated with the columns of the data.

dimData

The data associated with each dimension of the array.

dims

The size of the array.

dnames

The size of the array.

mat

This is the matrix. For extensibility, it cannot be written to directly and must be modified through methods.

metaData

Any data not part of the main data structure.

ncol

The number of columns in the data.

ndim

The number of dimensions of the array.

nrow

The number of rows in the data

rnames

The names of rows in the data.

rowData

A list of metadata associated with the rows of the data.

Methods

addSlices(number,dimension=2,mutate=TRUE)

This method must be extended. Extend a dimension by adding extra indices to the end.

Arguments
number - How many slices to add.
dimension - Which dimension should slices be added to.
mutate - Whether to change the original instance, or create a new one. If FALSE, the instance performing the method will be left unchanged, and a modified copy will be returned. If true, then the instance will modify itself and return nothing.
Value

If mutate=FALSE, a clone of this object will run the method and be returned. Otherwise, there is no return.

apply(FUNC,dimension=c(1,2))

This method must be extended. Apply a function to each slice.

Arguments
FUNC - The function to apply
dimension - The dimension(s) to hold fixed.
Value

An IncidenceArray with dimension equal to self$dims[dimension]

debug(string)

A function for debugging the methods of this class. It calls the browser command. In order for methods to opt into to debugging, they need to implement the following code at the beginning: if(<method_name> %in% private$.debug){browser()}. This method exists, because the debugger is not always intuitive when it comes to debugging R6 methods.

Arguments
string - The name(s) of methods to debug as a character vector

initialize(...)

This function should be extended. Create a new instance of this class.

Arguments
... - This function should take in any arguments just in case.

subset(...,mutate=TRUE)

This method must be extended. Take a subset of the matrix.

Arguments
... - dimensional indices in order.
mutate - Whether to modify the existing object, or return a modified copy.
Value

If mutate=FALSE, a clone of this object will run the method and be returned. Otherwise, there is no return.

undebug(string)

A function for ceasing to debug methods. Normally a method will call the browser command every time it is run. This command will stop it from doing so.

Arguments
string - The name(s) of the methods to stop debugging.

See Also

Inherits from : ArrayData

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require(abind)
SampleIncidenceArray  <- R6Class(
  inherit= AbstractIncidenceArray,
  public = list(
    initialize = function(data,dims = dim(data),dnames,dimData,metaData){
      private$.arr <- array(data,dims)
      if(!missing(dnames)){
        dimnames(private$.arr) <- dnames
        private$.dnames <- dnames
      }
      private$.dims = dim(data)
      private$.ndim = length(dim(data))
      if(!missing(dimData)){
        self$dimData <- dimData
      } else {
        self$dimData <- rep(list(list()),self$ndim)
      }
      if(!missing(metaData)){
        self$metaData <- metaData
      }
    },
    addSlices = function(number,dimension,mutate=TRUE){
      if(!mutate){
        return(self$clone(TRUE)$addSlices(number,dimension))
      }
      dims <- private$.dims
      dims[dimension] <- number
      private$.arr <-
        abind(
          private$.arr,
          array(NA,dims),
          along=dimension
        )
      private$.dims = dim(private$.arr)
      private$.dnames = dimnames(private$.arr)
    },
    subset = function(...,mutate=TRUE){
      if(!mutate){
        return(self$clone(TRUE)$subset(number,dimension))
      }
      private$.arr = private$.arr[...]
      private$.dnames = dimnames(private$.arr)
      private$.dims = dim(private$.arr)
      self$dimData <- 
        mapply(
          index = list(...),
          obj = self$dimData,
          function(index,obj){
            lapply(obj,function(x){x[index]})
          },
          SIMPLIFY = FALSE
        )
    }
  )
)

data = SampleIncidenceArray$new(array(1:27,c(3,3,3)))
data$addSlices(1,1)
data$addSlices(2,2)
data$addSlices(3,3)
data$arr
data$dims
data$subset(1:2,1:2,1:2)

HopkinsIDD/ForecastFramework documentation built on Nov. 10, 2019, 2:15 a.m.