Description Usage Arguments See Also Examples
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.
1 2 3 4 5 6 7 8 9 10 11 |
x |
the object |
name |
name of field or method |
value |
any object |
i |
like name |
j |
ignored |
... |
ignored |
defineRefClass
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 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"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.