0

Basically, this:

`[[<-.my_env` = function(env, name, value) {
  base::`[[<-`(env, name, value)
}

e = new.env()
class(e) = "my_env"

e[["x"]] = 1 
#> Error: C stack usage  7970388 is too close to the limit

I am not sure how to make the overloading work.

EDIT: This question is related but different to this one because I do want to target the environment(s) of the R6 object.

jakub
  • 4,774
  • 4
  • 29
  • 46

1 Answers1

0

So taking inspiration from the [[<-.data.frame method, stripping and reinstating the class attribute makes it work:

`[[<-.my_env` = function(env, name, value) {
  old_class = class(env)
  class(env) = NULL
  structure(base::`[[<-`(env, name, value), class = old_class)
}

e = new.env()
class(e) = "my_env"

e[["x"]] = 1

ls.str(e)
#> x :  num 1
jakub
  • 4,774
  • 4
  • 29
  • 46