How to test when condition returns numeric(0) in R
You could use ?length
:
isEmpty <- function(x) {
return(length(x)==0)
}
input <- c(3, 12);
if (!isEmpty(setdiff(input, 1:9))) {
stop ("not valid")
}
Here's another option identical(x, numeric(0))
. Here's an example (basically took everything from sgibb and replaced the key line as I'm lazy):
isEmpty <- function(x) {
return(identical(x, numeric(0)))
}
input <- c(3, 12)
if (!isEmpty(setdiff(input, 1:9))) {
stop ("not valid")
}