randy3k / collections

High-performance container datatypes for R
https://randy3k.github.io/collections
Other
103 stars 3 forks source link

Consider locking methods in the environment #26

Open tony-aw opened 7 months ago

tony-aw commented 7 months ago

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.