findUnusedArgs: Find unused parameters and local variables

Description Usage Arguments Value Author(s) See Also Examples

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

1
2
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
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 Aug. 11, 2019, 12:35 a.m.