Skip to content
Prev 58635 / 63424 Next

eval and Calling Frames

Hi Brodie,

I wouldn't use the rlang tests as a measure of backward compatibility.
Your patch changes the structure of the `parent.frame()` hierarchy,
which is likely to be disruptive with packages that do weird NSE stuff
(and so, not rlang ;-p). Currently things are set up so that the
parent frame of the evaluated call is the "target" `eval()` context,
which itself has for parent the "closure" `eval()` context.

For example, with:

```
foo <- function() eval(quote(bar()))
bar <- function() EXPR()
```

The current hierarchy (as defined by `parent.frame()`) is:

```
    ?
 1. ??global::foo()
 2.   ??base::eval(quote(bar()))
 3.     ??base::eval(quote(bar()))   <- This is the same frame env as foo()
 4.       ??global::bar()
 5.         ??global::EXPR()
```

With your patch, it becomes:

```
    ?
 1. ??global::foo()
 2.   ??base::eval(quote(bar()))
 3.   ? ??base::eval(quote(bar()))
 4.   ??global::bar()
 5.     ??global::EXPR()
```

I agree the second hierarchy is preferable. See also the documentation
of `filter.callframes` in `?Rprof` which patches up things so that the
`eval()` frames are filtered out from the trailing backtrace
branch. This wouldn't be necessary with the second hierarchy.

Best,
Lionel
On 6/1/20, brodie gaslam via R-devel <r-devel at r-project.org> wrote: