moodymudskipper / flow

View and Browse Code Using Flow Diagrams
https://moodymudskipper.github.io/flow/
Other
395 stars 26 forks source link

following arguments around #168

Open moodymudskipper opened 6 months ago

moodymudskipper commented 6 months ago

Use case:

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.