I'm trying to figure out how to do some data quality checking on a code.
Suppose I have
x <- list(1,2,T)
y <- list(1,2,3)
I want to be able to apply a function which will flag 'x' as having bad data.
if(any(is.logical(x))) stop('Bad data')
but
if(any(is.logical(y)))
won't trigger an error.
I know I could do it with a for loop, but I'm hoping to find a simpler solution.
For Loop Solution
for (tmp in x) {if (is.logical(tmp)) stop('Bad data')}
solution is to use sapply.
Note that using any and sapply is significantly slower than using a for loop.
Using vapply as suggested below