moodymudskipper / flow

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

Filter by regular expression in flow_view_deps() #106

Closed krlmlr closed 1 year ago

krlmlr commented 2 years ago

Should trim, promote, demote and hide support regular expressions? How to distinguish regexes from length-one character vectors?

moodymudskipper commented 2 years ago

I had thought about it but didn't find a satisfying solution at the time so skipped it.

A few ways to do it :

moodymudskipper commented 2 years ago

I think we can have pkg_subset(pkg, subset = c("all", "exports", "imports", "reexports", ...), pattern = NULL, predicate = NULL, value = FALSE, prefix = TRUE) which would return a character vector of "pkg::fun" and "pkg:::fun" strings (or just "fun" if prefix is FALSE, or a named list if value is TRUE).

This would be a fairly useful utility in general too.

predicate is applied on the packaged object so we can restrict to functions, to S3 methods, to functions that have a given class etc.

subset would use getNamespaceExports, getNamespaceImports, ls(asNamespace(pkg)) etc so we can easily be restricted to a category of functions. Maybe S3 and S4 methods, low level language wrappers, runtime defined functions etc could be there too.

moodymudskipper commented 1 year ago

pkg_subset() would be a useful function, but better in its own package, one that would define package objects and utilities to manipulate them ideally. Not really in scope here.

I think the easiest, since we don't use names yet, it to treat differently unnamed element and element named "pattern", the latter define a regex, no name means "fixed".

moodymudskipper commented 1 year ago

I would also like to support promoting/demoting full packages, so we can use the package name too. An issue is that with 3 ways of selecting we might have an intersection between demote and promote for instance, the result is ambiguous in this case. It makes sense that explicitly provided names have priority over regex, but what about packages ? Also what about restricting a pattern to a given package.

moodymudskipper commented 1 year ago

@krlmlr see PR description for a way to handle it from now on