Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It is possible to overwrite methods in R6 objects #19

Closed
richfitz opened this issue Aug 11, 2014 · 3 comments

Comments

@richfitz
Copy link

commented Aug 11, 2014

Once an R6 object has been constructed, it is possible to overwrite its methods, which seems undesirable:

Thing <- R6::R6Class("Thing",
                     public=list(
                       a=1L,
                       f=function() a))
obj <- Thing$new()
obj$f() # 1L
obj$f <- NULL # is allowed
obj$f() # Error: attempt to apply non-function

And of course, putting the method "back" doesn't work because the environment of that function is wrong:

obj$f <- function() a
obj$f() # Error: object 'a' not found

Is there any way of easily preventing this happen without sacrificing the speed goals of R6?

@richfitz

This comment has been minimized.

Copy link
Author

commented Aug 11, 2014

Sorry - should have said: this affects the current CRAN version (1.0.1), as well as development version a1177fc

@wch

This comment has been minimized.

Copy link
Member

commented Aug 11, 2014

Yes, it probably makes sense to lock the bindings for methods when lock=TRUE. As it is, that option stops you from adding new variables, but doesn't prevent modifying existing ones.

@wch wch closed this in 87d8fb2 Aug 11, 2014

@wch

This comment has been minimized.

Copy link
Member

commented Aug 11, 2014

I decided that method bindings should always be locked; if users really want to modify them, they can always unlock the bindings themselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.