removeConstIf: Eliminate dead if code

View source: R/ifLiteral.R

removeConstIfR Documentation

Eliminate dead if code

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

removeConstIf(expr)

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


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 May 9, 2024, 3:04 a.m.