Discerning intra-code dependencies


Are there any good tools for discovering _intra_package dependencies (dependencies within a package - like a function defined in the package being called elsewhere in the package)? Unfortunately, since dependencies with other packages are a well-explored issue, content on _inter_package dependencies (dependencies with other packages) drown out my results.

For example, if I'm considering changes to a function to my package, it would be awesome to have some sort of utility to search all of the files in my package for the string containing my function name and visualize where else the function name shows up in the R/ folder (even better if also in documentation, vignettes, RMarkdown templates, etc.; and both upstream and downstream interactions might also be helpful.)

Obviously, it's pretty trivial to just search through all the text files on the command line, but I'm interested if anyone has any other good approaches.

Keyboard shortcuts

In RStudio, you can use the Find in files toolbox behind Edit menu (CTRL+ SHIFT + F on windows). It will look for keyword inside each file of the current project. Pretty useful ! And I prefere it rather the the command line.

I use it for searching where a funtion is used when I develop.


You might want to try https://github.com/r-lib/pkgapi

It gives you a function call map, including file names and positions, for all functions and function calls.


Thanks so much -- looking forward to playing around with this!


Thanks -- that really is super useful! Already saved me a headache with one dependency that was completely not on my radar


In addition to the tools mentioned (Ctrl/Cmd-Shift-F is of course a life savior, especially when trying to understand code written by others), I know of (but haven't tried):

mvbutils::foodweb() https://www.r-bloggers.com/r-function-of-the-day-foodweb-2/

CodeDepends::makeCallGraph() https://cran.r-project.org/web/packages/CodeDepends/vignettes/intro.html