What is the difference between parent.frame() and parent.env() in R; how do they differ in call by reference?
It would be helpful if someone can illustrate this with a simple example? Also, where would it be useful to use parent.frame() instead of parent.env() and vice versa. parent.env is the environment in which a closure (e.g., function) is defined. parent.frame is the environment from which the closure was invoked. f = function() c(f=environment(), defined_in=parent.env(environment()), called_from=parent.frame()) g = function() c(g=environment(), f()) and then > g() $g <environment: 0x14060e8> $f <environment: 0x1405f28> $defined_in <environment: R_GlobalEnv> $called_from <environment: 0x14060e8>