removeConstIf: Eliminate dead if code

Description Usage Arguments Value Author(s) Examples

View source: R/ifLiteral.R

Description

This function identifies and eliminates parts of if-else expressions that are known at analysis time to be unreachable. These are of the form if(FALSE) {...} . This is typically used to "comment" out code. We want to eliminate it both to simplify and clarify the code and also reduce the code we would compile (see RLLVMCompile.

Usage

1

Arguments

expr

the R function or expression to process

Value

The potentially modified expression/function with any dead if statements eliminated.

Author(s)

Duncan Temple Lang

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
f = function()
{
  if(length(x) > 10)
      print(x)
  else if(length(x) > 5 && FALSE)
      show(x)
  else
      cat("x is small\n")
}

removeConstIf(f)

duncantl/CodeAnalysis documentation built on Jan. 20, 2020, 5:17 a.m.