Description Fields Methods See Also Examples
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.
This is the full array. For extensibility, it cannot be written to directly and must be modified through methods.
A list of metadata associated with the cells of the data.
The names of columns in the data.
A list of metadata associated with the columns of the data.
The data associated with each dimension of the array.
The size of the array.
The size of the array.
This is the matrix. For extensibility, it cannot be written to directly and must be modified through methods.
Any data not part of the main data structure.
The number of columns in the data.
The number of dimensions of the array.
The number of rows in the data
The names of rows in the data.
A list of metadata associated with the rows of the data.
This method must be extended. Extend a dimension by adding extra indices to the end.
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. |
If mutate=FALSE
, a clone of this object will run the method and be returned. Otherwise, there is no return.
This method must be extended. Apply a function to each slice.
FUNC | - | The function to apply |
dimension | - | The dimension(s) to hold fixed. |
An IncidenceArray with dimension equal to self$dims[dimension]
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.
string | - | The name(s) of methods to debug as a character vector |
This function should be extended. Create a new instance of this class.
... | - | This function should take in any arguments just in case. |
This method must be extended. Take a subset of the matrix.
... | - | dimensional indices in order. |
mutate | - | Whether to modify the existing object, or return a modified copy. |
If mutate=FALSE
, a clone of this object will run the method and be returned. Otherwise, there is no return.
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.
string | - | The name(s) of the methods to stop debugging. |
Inherits from : ArrayData
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.