Private-class {aoos} | R Documentation |
Private class
Description
This is a virtual class to be contained in other class definitions. It overrides the default subset functions $
and [[
such that private member of a class can not be accessed. Private is every object which has a name with a leading "." (grepl("^\\.", name)
). After this check the standard method for class 'envRefClass' is called or an error is reported.
Usage
## S4 method for signature 'Private'
x$name
## S4 replacement method for signature 'Private'
x$name <- value
## S4 method for signature 'Private'
x[[i, j, ...]]
## S4 replacement method for signature 'Private'
x[[i, j, ...]] <- value
Arguments
x |
the object |
name |
name of field or method |
value |
any object |
i |
like name |
j |
ignored |
... |
ignored |
See Also
Examples
ClassWithPrivateField <- defineRefClass({
Class <- "ClassWithPrivateField"
contains <- "Private"
.p <- "numeric"
getP <- function() .p
setP <- function(v) .self$.p <- v
})
test <- ClassWithPrivateField()
stopifnot(inherits(try(test$.p), "try-error"))
stopifnot(inherits(try(test$.p <- 2), "try-error"))
stopifnot(inherits(try(test[[".p"]]), "try-error"))
stopifnot(inherits(try(test[[".p"]] <- 2), "try-error"))
[Package aoos version 0.5.0 Index]