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"))
Run the code above in your browser using DataLab