nested_if: Simplify the treatment of recursive/nested 'if'-statements.

Description Usage Arguments Value

View source: R/nested_if.R

Description

Recursive/nested if-statements can pop up when the latter statements need the former statements to be true in order to be well-defined, in which case it might be rather messy to formulate an "all-must-be-TRUE" statement. Such nested if-statements can e.g. occur when inspecting objects stored in recursive lists where different branches can have quite different structures, in which case any statement regarding a given level of a list must be preceeded by a test of the kind !identical(list$level, NULL).

Usage

1
2
nested_if(if_list = list(), expr_all_TRUE = TRUE,
  expr_not_all_TRUE = invisible(NULL), env = parent.frame())

Arguments

if_list

A list of the statements we want to test, default value list().

expr_all_TRUE

The result to return if the nested structure turns out to contain well defined stuff that passes the tests. The default value for this is TRUE.

expr_not_all_TRUE

The result to return if it turns out that something goes wrong (not defined, or false statements). The default value for this is NULL.

env

The environment at which the statements should be evaluated, the default value is parent.frame()

Value

The result will be TRUE if all the statements given in if_list is TRUE, otherwise the result will be FALSE. The result will be FALSE if if_list has length zero.


LAJordanger/leanRcoding documentation built on Feb. 27, 2020, 4:42 p.m.