I've inherited a large R codebase which has grown over a few years and a few different developers. It contains many things I'd like to delete: - Unused functions - Variable definitions that are never called - Unreachable code I'd write that myself, it would even be fun, but I don't want to reinvent the wheel. Is there an R package that can find these things? I've heard of lintr, but I'm not sure if it's the right tool, since, unfortunately, the code is in a folder (not a package) with many R files that are sourced from one master file and lintr can only check a single file or an actual package, from what I understand. A workaround of course would be to concatenate all files into one R script. I'd appreciate any hints on how to best solve this. Thanks in advance, Alex
mvbutils::foodweb produces a graphical display of the hierarchy (or network or ...) of function calls. Isolated functions are not called. This might help you. -- Mike On Wed, Nov 15, 2017 at 12:44 AM, Alexander Engelhardt <alex at chaotic-neutral.de> wrote:> I've inherited a large R codebase which has grown over a few years and a few > different developers. > > It contains many things I'd like to delete: > - Unused functions > - Variable definitions that are never called > - Unreachable code > > I'd write that myself, it would even be fun, but I don't want to reinvent > the wheel. > Is there an R package that can find these things? > > I've heard of lintr, but I'm not sure if it's the right tool, since, > unfortunately, the code is in a folder (not a package) with many R files > that are sourced from one master file and lintr can only check a single file > or an actual package, from what I understand. A workaround of course would > be to concatenate all files into one R script. > > I'd appreciate any hints on how to best solve this. > > Thanks in advance, > Alex > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Thanks, that helps! The visualization is very messy, because I have about 100 functions, but foodweb() returns a matrix of which function calls which, and the functions callers.of("myfunc") and callees.of("myfunc") do exactly what I was looking for. ?- Alex On 11/15/2017 10:44 AM, Michael Hannon wrote:> mvbutils::foodweb produces a graphical display of the hierarchy (or > network or ...) of function calls. Isolated functions are not called. > This might help you. > > -- Mike > > > On Wed, Nov 15, 2017 at 12:44 AM, Alexander Engelhardt > <alex at chaotic-neutral.de> wrote: >> I've inherited a large R codebase which has grown over a few years and a few >> different developers. >> >> It contains many things I'd like to delete: >> - Unused functions >> - Variable definitions that are never called >> - Unreachable code >> >> I'd write that myself, it would even be fun, but I don't want to reinvent >> the wheel. >> Is there an R package that can find these things? >> >> I've heard of lintr, but I'm not sure if it's the right tool, since, >> unfortunately, the code is in a folder (not a package) with many R files >> that are sourced from one master file and lintr can only check a single file >> or an actual package, from what I understand. A workaround of course would >> be to concatenate all files into one R script. >> >> I'd appreciate any hints on how to best solve this. >> >> Thanks in advance, >> Alex >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.