How to test when condition returns numeric(0) in R

r

Solution

You could use `?length`:

isEmpty <- function(x) {
    return(length(x)==0)
}

input <- c(3, 12);

if (!isEmpty(setdiff(input, 1:9))) {
    stop ("not valid")
}

Problem

Let's imagine you would like to construct a simple test based on the condition `setdiff(input, 1:9)`. How can I construct an ``` if isnotempty(setdiff(input, 1:9)) stop ("not valid") ``` statement which stops execution when input is `c(3, 12)` but continues when input is `c(2,5,7)` say? Many thanks, Bertie

Original source