test <- defineClass("test", {
x <- "Working ..."
.y <- 0
doSomething <- public(function() {
self$.y <- .y + 1
cat(x(), "\n")
invisible(self)
})
})
instance <- test()
## Not run: ------------------------------------
# instance$.y # error
## ---------------------------------------------
instance$doSomething()$doSomething()
instance$x()
instance$x(2)
instance$x()
# Example for reference classes as field
MoreTesting <- defineClass("MoreTesting", {
refObj <- test()
})
instance <- MoreTesting()
instance$refObj$x()
Run the code above in your browser using DataLab