“User” constructor for R6 class in R

拟墨画扇 提交于 2019-12-02 02:26:12

Since R6 classes are actually envoronments, you can use className$constructorName to archieve this result.

library(R6)

ERes <- R6Class(
  "ERes",
  public = list(
    eTable = NULL,
    eList = NULL,
    initialize = function(eTable, eList){
      self$eTable <- eTable
      self$eList <- eList
    }
  )
)

ERes$userConstructor <- function(someData){
  ERes$new(table(someData), as.list(someData))
}

myObject <- ERes$userConstructor(rpois(100, 5))

myObject$eTable
# someData
#  0  1  2  3  4  5  6  7  8 10 
#  3  3  7 16 16 20 14 10  9  2 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!