Private: Private class

Description Usage Arguments See Also Examples

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## 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

defineRefClass

Examples

 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"))

wahani/aoos documentation built on May 27, 2017, 11:54 p.m.