Here, only the first call to f1() is incorrect, and the 2nd call is what I expect.
The actual error I encountered while working on reticulate was slightly different, and more difficult to reproduce. In C I was doing something like this (simplified for this issue):
save_r_trace() works fine when called from a regular R function, but fails when called from C like in the snippet above, because the parent of the evaluation frame there is reported as 0 (I'm guessing because the package namespace is a topenv? Sidenote, the docs should perhaps be updated, parent == 0 is documented as only occurring if parent == globalenv()).
If I drop into a debugger in save_r_trace() I see this:
In attempting to produce a reprex, I found two other different failure modes :crying_cat_face:.
First failure mode with reprex in the mix:
Created on 2023-04-26 with reprex v2.0.2
Both calls to
f1()
in the reprex give an incorrect result. Running it in the IDE directly (without reprex), I see this:Here, only the first call to
f1()
is incorrect, and the 2nd call is what I expect.The actual error I encountered while working on reticulate was slightly different, and more difficult to reproduce. In C I was doing something like this (simplified for this issue):
with this in the reticulate namespace:
save_r_trace()
works fine when called from a regular R function, but fails when called from C like in the snippet above, because the parent of the evaluation frame there is reported as0
(I'm guessing because the package namespace is a topenv? Sidenote, the docs should perhaps be updated,parent == 0
is documented as only occurring if parent == globalenv()).If I drop into a debugger in
save_r_trace()
I see this:Here, the value supplied to
bottom
appears to have not effect on the return value.