r-lib / R6

Encapsulated object-oriented programming for R
https://R6.r-lib.org
Other
407 stars 56 forks source link

"lock" parameter is being ignored? #52

Closed daattali closed 9 years ago

daattali commented 9 years ago

From my understanding of the documentation, if a class is defined with lock = TRUE (which is the default), then adding new members should not be allowed. But I'm not seeing this restriction happening in practice.

Test <- R6::R6Class(
  "test",
  lock = TRUE,

  public = list(
    anything = function(){}
  )
)

Test$set("public", "setName", function(s) s)
> names(Test$public_methods)
[1] "anything" "setName" 

Maybe I'm misinterpreting what lock is doing.


R 3.1.3, R6 2.0.1

wch commented 9 years ago

The lock argument actually means that the objects (not the generator) can't have new fields added to them. But it would be useful to have a lockClass argument as well.