The same error message results not only for null
but also for e.g. factor(0)
. In this case, the query must be if(length(element) > 0 & otherCondition)
or better check both cases with if(!is.null(element) & length(element) > 0 & otherCondition)
.