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

locked objects + derived classes #129

Open
kevinushey opened this issue Aug 10, 2017 · 3 comments
Open

locked objects + derived classes #129

kevinushey opened this issue Aug 10, 2017 · 3 comments
Labels
feature a feature request or enhancement

Comments

@kevinushey
Copy link

The following snippet of code fails:

library(R6)

Base <- R6Class(
  "Base",
  public = list(
    initialize = function() {
      self[["Hello"]] <- 1
    }
  ),
  lock_objects = FALSE
)
Base$new()  # okay

Derived <- R6Class("Derived", inherit = Base)
Derived$new()  # barf

The error:

> Derived$new()
Error in self[["Hello"]] <- 1 : 
  cannot add bindings to a locked environment

Should derived classes also inherit the lockedness from their parent environment?

@wch
Copy link
Member

wch commented Aug 10, 2017

The behavior you're proposing does seem reasonable... but then what do you suggest as the default value for lock_objects?

@kevinushey
Copy link
Author

I would lean towards lock_objects = FALSE, unless modifying that makes it too easy for users to do things that could break R6 in weird ways. (I think modifying properties on self is probably fine in most cases?)

@wch
Copy link
Member

wch commented Aug 11, 2017

I think it's too late to change the default behavior to not lock objects -- and I think that it's good that they're locked by default.

What I meant was, it seems reasonable to allow inheriting the lock status, but if we were to change to that behavior, the current default of lock_objects = TRUE doesn't make sense. So the question is what could it be changed to that makes top-level classes default to being locked, but also makes subclasses inherit the lock status by default?

@hadley hadley added the feature a feature request or enhancement label Apr 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants