findUnusedArgs: Find unused parameters and local variables

findUnusedArgsR Documentation

Find unused parameters and local variables

Description

These functions analyze an R function and identify parameters or local variables that are not used in the code.

It is useful to remove any dead code with removeConstIf and removeAfterReturn. This is done by default.

Usage

findUnusedArgs(fun, remove = TRUE, clean = TRUE)
findUnusedAssignments(fun, remove = TRUE, clean = TRUE)

Arguments

fun

the function to analyze

clean

a logical value controlling whether we remove dead code before processing the function with removeConstIf and removeAfterReturn

remove

a logical value controlling whether the code eliminates the dead code and returns the modified code.

Value

A character vector giving the names of the parameters or local variables that are not used.

Author(s)

Duncan Temple Lang

See Also

removeConstIf, removeAfterReturn

Examples

f =
function(a, b, u)
{
  z = a + b
  ans = g(z)
}

findUnusedArgs(f)

f =
function()
{
  a = 1
  b = 2
  c = 3
  d = 10
  a + c
}

findUnusedAssignments(f)

duncantl/CodeAnalysis documentation built on Feb. 21, 2024, 10:49 p.m.