moodymudskipper / flow

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

FR: Show non used objects in flow_view_uses? #174

Closed llrs closed 3 months ago

llrs commented 3 months ago

I am using more flow to inspect my own packages to improve code and follow the "Don't repeat yourself" principle. One particular use case is if I define a new helper function and I need to go back and find where it might be used.

I don't expect flow to check the code and compare an object with the code but it would be nice to have flow_view_uses to have an argument to display other functions/code aren't using the object. The way I see I could use flow::flow_view_uses(omit, all = TRUE) so that all (exported) objects of the package/environment would be shown (by default it would be FALSE). This way it might help to find some definitions I need to review to see if omit would be helpful there.

I am not sure if it fits well with the scope of the package, as I am asking for a diagram of objects/functions with no flow between them.

moodymudskipper commented 3 months ago

I think if there is no relationship between blocks a diagram might not be the right fit. And this would really be useful only for a small package, or the diagram will become huge.

Now I think flow could contain functions that describe dependencies between functions without drawing diagrams.

Alternately you can show everything on a single diagram:

devtools::load_all()
flow::flow_view_deps(as.list(asNamespace("yourpkg")))

Or we can fetch the data from the diagram and do some wrangling :

fl <- flow::flow_view_uses(yourpkg::your fun)
setdiff(getNamespaceExports("yourpkg"), c(fl$data$fun, "yourfun"))
setdiff(names(asNamespace("yourpkg")), c(fl$data$fun, "yourfun"))

Do those help ?

llrs commented 3 months ago

Yes, this helps. Many thanks.

A function that exposes data and another that plots it is great in case the end-user wants to use other plotting methods or customize it. It will also help with #127.