if_na_null | R Documentation |
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.
if_na_null(test, na = FALSE, null = FALSE)
test |
condition. can only have length 0 or length 1 |
na |
returned if the condition has a missing value |
null |
passed to ifelse |
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) })
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.