collections icon indicating copy to clipboard operation
collections copied to clipboard

Consider locking methods in the environment

Open tony-aw opened this issue 1 year ago • 0 comments

Hi,

Tiny suggestion: Automatically lock all the methods in the environments that are used for dictionaries, stacks, etc. Otherwise, the user can accidentally remove methods (like set()), forcing the user to cre-create the entire object.

Demonstration for clarification:

> d <- dict(list(apple = 5, orange = 10))
> d$set <- NULL
> d$set # this is now changed to "NULL"
NULL
> 
> d <- dict(list(apple = 5, orange = 10))
> lockBinding("set", d) # d$set() is now safe
> d$set <- NULL
Error in d$set <- NULL : cannot change value of locked binding for 'set'
> d$set("banana", 3) # this still works

Or is there some issue with locking methods that I don't see?

Kind regards,

Tony.

tony-aw avatar Apr 03 '24 09:04 tony-aw