This function takes a series of conditions and corresponding values, and builds an equation consisting of nested if statements.
ls_eq_nestIfs(conditions, values, elseExpr, quoteValues = FALSE)
The conditions - in the right order, i.e. in the produced expression if nested if statements, the first condition in this list will be checked first, then the second, etc.
The values corresponding to each condition (in the same order!).
The value to return if there are no matches.
Whether to use double quotes to quote the values.
A character value.
### Relatively simple example with four levels of nesting
ls_eq_nestIfs(c("age.NAOK > 80",
"age.NAOK > 65",
"age.NAOK > 40",
"age.NAOK > 20"),
c("Respectable",
"Roughly retired",
"Roughly middle-aged",
"Quite young"),
"Very young",
quoteValue=TRUE);
#> [1] "if(age.NAOK > 80, \"Respectable\", if(age.NAOK > 65, \"Roughly retired\", if(age.NAOK > 40, \"Roughly middle-aged\", if(age.NAOK > 20, \"Quite young\", \"Very young\"))))"