if_na_null: This function makes sure you know what to expect when...

Description Usage Arguments Examples

View source: R/shorthands.R

Description

This function makes sure you know what to expect when evaluating uncertain results in an if-clause. In most cases, you should not use this function, because it can lump a lot of very different cases together, but it may have some use for fool-proofing certain if-clauses on formr.org, where a field in a survey may either not exist, be missing or have a value to check.

Usage

1
if_na_null(test, na = FALSE, null = FALSE)

Arguments

test

condition. can only have length 0 or length 1

na

returned if the condition has a missing value

null

passed to ifelse

Examples

1
2
3
4
5
6
testdf = data.frame(test1 = 1, test2 = NA)
if ( if_na_null(testdf$test1 == 1) ) { print("go on") }
if ( if_na_null(testdf$test2 == 1) ) { print("not shown") }
if ( if_na_null(testdf$test3 == 1) ) { print("not shown") }
tryCatch({ if ( if_na_null(testdf2$test1 == 1) ) { print("causes error") } }, 
   error = function(e) { warning(e) }) 

grebbel/formr_test documentation built on May 17, 2019, 8:34 a.m.