You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Base class declaration function: Change SetRefClass(... to R6Class(
Syntax for inheritance: Change: contains = "openmi.om.linkableComponent", to inherit = openmi.om.linkableComponent, (notice no quot3es around class name -- very important)
referencing the object local fields. In R6, need to use the self$ prefix before class attributes, so data changes to self$data
Referencing super class methods:
change "callSuper()" to "super$methodname()"
The "<<-" for assignment of self attributes goes to "<-"
S4 version:
#****************************
# Override logState() method and has write method on finish()
#****************************
#' The base class for logging component data.
#'
#' @param
#' @return reference class of type openmi.om.linkableComponent
#' @seealso
#' @export openmi.om.logger
#' @examples
openmi.om.logger <- setRefClass(
"openmi.om.logger",
fields = list(
directory = "character",
path = "character",
filename = "character",
outputs = "ANY"
),
contains = "openmi.om.linkableComponent",
# Define the logState method in the methods list
methods = list(
update = function () {
callSuper()
},
initialize = function () {
callSuper()
},
logState = function () {
callSuper()
if (!is.xts(outputs)) {
# first time, we need to initialize our data columns which includes timestamp
# @todo: be more parsimonius?
outputs <<- xts(data.frame(data), order.by = as.POSIXct(data$thistime))
} else {
outputs <<- rbind(outputs, xts(data.frame(data), order.by = as.POSIXct(data$thistime)))
}
}
)
)
R6 version
#****************************
# Override logState() method and has write method on finish()
#****************************
#' The base class for logging component data.
#'
#' @param
#' @return reference class of type openmi.om.linkableComponent
#' @seealso
#' @export openmi.om.logger
#' @examples
openmi.om.logger <- RClass(
"openmi.om.logger",
inherit = openmi.om.linkableComponent,
public = list(
directory = "character",
path = "character",
filename = "character",
outputs = "ANY"
),
inherit = openmi.om.linkableComponent,
# Define the logState method in the methods list
methods = list(
update = function () {
callSuper()
},
initialize = function () {
callSuper()
},
logState = function () {
callSuper()
if (!is.xts(outputs)) {
# first time, we need to initialize our data columns which includes timestamp
# @todo: be more parsimonius?
outputs <<- xts(data.frame(data), order.by = as.POSIXct(data$thistime))
} else {
outputs <<- rbind(outputs, xts(data.frame(data), order.by = as.POSIXct(data$thistime)))
}
}
)
)
The text was updated successfully, but these errors were encountered:
SetRefClass(...
toR6Class(
contains = "openmi.om.linkableComponent",
toinherit = openmi.om.linkableComponent,
(notice no quot3es around class name -- very important)self$
prefix before class attributes, sodata
changes toself$data
S4 version:
R6 version
The text was updated successfully, but these errors were encountered: