'Overloading `[[<- ` leads to C stack usage error
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.
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |