Dear R Users, Are there any tools to extract the function names called by reverse-dependencies? I would like to group these functions using clustering methods based on the co-occurrence in the reverse-dependencies. Utility: It may be possible to split complex packages into modules with fewer reverse-dependencies. Package pkgdepR may offer some of the functionality; but I did not have time to fully explore it: https://cran.r-project.org/web/packages/pkgdepR/index.html If such tools are not yet available, I have opened an issue on GitHub and would like to collect any ideas: https://github.com/discoleo/PackageBrowser/issues/1 There are some model packages that could be used to test the clustering: 1) Rcpp, xml: the core-functionality will always be needed; splitting into modules may not be possible/useful; 2) pracma: most reverse-dependencies are likely using only a small subset of the functions in pracma; (there was some discussion on R-package-devel about reverse dependencies a few weeks ago) 3) survival: I have no idea in which category it falls - but it has a lot of reverse-dependencies; Note: I missed some important functionality from the pkgsearch package. I have started therefore work on a new package (PackageBrowser) - although it is not yet published on CRAN: https://github.com/discoleo/PackageBrowser It does not yet process recursively the reverse-dependencies; although this does not seem a big challenge. The real challenge is to parse the code and extract function names. I did some work in the past, but never had time for a full implementation. Many thanks, Leonard [[alternative HTML version deleted]]
? Sat, 24 Feb 2024 03:08:26 +0000 Leo Mada via R-help <r-help at r-project.org> ?????:> Are there any tools to extract the function names called by > reverse-dependencies?For well-behaved packages that declare their dependencies correctly, parsing the NAMESPACE for importFrom() and import() calls should give you the explicit imports. (What if the package imports the whole dependency? The safe assumption is that all functions are used, but it comes with false positives. You could also walk the package code looking for function names that may belong to the imported package, but that may involve both false positives and false negatives.) For the rest of the imports and uses of weak dependencies, you'll have to walk the package code looking for the uses of the `::` operator. See how R CMD check walks the package code in functions tools:::.check_packages_used and codetools::checkUsage. A less-well-behaved package can always load a namespace during runtime and choose the functions to call depending on the phase of the moon or weather on Jupiter. For these, like for the halting problem, there's no general solution: the package could be written to say, "if Leonard's function says I'm about to call foo::bar, I won't do it, otherwise I will". -- Best regards, Ivan