0

If I run the following code in R, R will not be responsive after the last command. Does anybody know what causes the problem and how to set the parent environment of an environment? (BTW, I am aware of the difference between parent.frame and parent.env What is the difference between parent.frame() and parent.env() in R; how do they differ in call by reference?)

e1=environment()
e2=environment()
parent.env(e1)=e2
parent.env(e1)
Community
  • 1
  • 1
user1424739
  • 11,937
  • 17
  • 63
  • 152
  • 3
    `environment()` by itself is the global environment. So you are creating e1 and e2 are global environment. If you check `?parent.env`, some examples are there `e1 <- new.env(parent = baseenv()) ; e2 <- new.env(parent = e1)` – akrun Jul 18 '15 at 13:42
  • If R becomes unresponsive, I would think that to be bug, so you might post a question on the R-devel mailing list. It's not a segfault but it's certainly undesirable. Perhaps you meant to use `new.env()` instead of `environment()` ? – IRTFM Jul 18 '15 at 19:51

1 Answers1

1

Is this what you wanted to achieve?

e1 <- new.env()
e2 <- new.env()
parent.env(e1 <- e2
parent.env(e1)
#<environment: 0x10dfaba70>
IRTFM
  • 258,963
  • 21
  • 364
  • 487