-
Notifications
You must be signed in to change notification settings - Fork 26
Description
Use case:
- I provide a parameter
arg1to a function - This parameter is used to build some more variables, that in turn are passed to other functions
- Some other variables are defined from those, and passed around and so on
- Question: show me the tree of all functions affected by this argument
No strong opinion yet on the api but it seems to me the result is just a subset of flow_view_deps, so maybe in practice that's just an arg = NULL argument to flow_view_deps() ?
The easier way to do it is just detect assignments that have the arg on the rhs and collect the lhs recursively (considering assignment functions foo<- as well). then we keep deps on the intersection on callers (consider that with things like x <- foo(y, bar(arg)) both foo and bar must be considered).
The harder way is to acknowledge that we might have placeholder/temp variables used for different purposes, so we have to implement something like flow_view_vars()'s technology to be more accurate.
We could also have a run() variant, I think with bagtools::chatty() I had a trick to track an object, and maybe objects that used it, using active bindings that assessed their environment and call anytime they were accessed.
We can have something like :
my_function(x, follow_me(y))
where follow_me() (flow_me() ?) can make y one such sneaky active binding, and we trace sys.fun(1) so it prints the flow diagram on exit. I think using follow_me() several times there comes basically for free.
We might not be able to guess the calling function when not called from the top level, so maybe we can have follow_me(arg, fun = sys.function(1)) for flexibility, and a bit of free transparency on the magic.