AbstractRelationalTables: AbstractRelationalTables

Description Fields Methods See Also Examples

Description

A class for storing data in multiple interrelated tables. Each table relates to the other tables through keys.

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.

frame

The data frame this class is responsible for.

keys

A list containing the primary keys for each table

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.

tables

A list of tables of data

Methods

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.

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 : RelationalData

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
library(dplyr)
library(reshape2)
SampleRelationalTables <- R6Class(
  inherit = AbstractRelationalTables,
  public = list(
    initialize = function(...){
      private$.tables = list(...)
      if(!all(sapply(private$.tables,function(x){is.data.frame(x)}))){
        stop("All arguments must be data frames")
      }
    },
    updateFrame = function(){
      private$.frame = Reduce(x = private$.tables,f = left_join)
    },
    updateArray = function(){
      val <- names(self$frame)[1]
      dims <- names(self$frame[2:ncol(self$frame)])
      private$.arr <- self$frame %>%
        group_by_(.dots=setNames(dims,NULL)) %>%
        summarize_all(sum) %>% 
        ungroup() %>%
        acast(as.formula(paste(dims,collapse='~')),value.var=val)
      mode(private$.arr) = 'numeric'
      private$.dims = dim(private$.arr)
      private$.nrow = private$.dims[1]
      private$.ncol = private$.dims[2]
      private$.ndim = length(private$.dims)
      private$.dnames = dimnames(private$.arr)
    }
  ),
  active = list(
    mat = function(value){
      if(self$ndim <= 2){
        return(self$arr)
      }
      return(extract(private$.arr,indices = rep(self$ndim-2,x=1),dims = 3:self$ndim,drop=TRUE))
    }
  )
)

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