Is there a tool to find unused functions?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Is there a tool to find unused functions?

Alexander Engelhardt
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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Is there a tool to find unused functions?

Michael Hannon-2
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
<[hidden email]> 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
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Is there a tool to find unused functions?

Alexander Engelhardt
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
> <[hidden email]> 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
>>
>> ______________________________________________
>> [hidden email] 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.
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.