I recently inherited a large R codebase that has grown over many years and several different developers. It contained a lot of commented-out code and old functions that are not called anymore.
Many other languages have dedicated tools, and sometimes even compiler flags, that can find functions that are defined but never used. In R, this can be done by the
foodweb() function in the
mvbutils package. In its most basic form, you source all
.R files to get the functions into your workspace, and then call
This outputs a plot that shows how the functions interact - i.e., which function is called by which. Those functions without a connection stand alone, without any edge connecting it.
In my codebase, however, this plot was messy, so I had to dive into the object that
foodweb returns. This is how I found all uncalled functions in my current workspace: