14.7 Constructing a bank account class
BankAccount <- R6Class("BankAccount", list(
owner = NULL,
type = NULL,
balance = 0,
initialize = function(owner, type) {
stopifnot(is.character(owner), length(owner) == 1)
stopifnot(is.character(type), length(type) == 1)
},
deposit = function(amount) {
self$balance <- self$balance + amount
invisible(self)
},
withdraw = function(amount) {
self$balance <- self$balance - amount
invisible(self)
}
))