Function to identify problematic datatypes
- by Zach
I just spent several hours debugging some R code, only to discover that the error was due to an Inf that had sneaked in during my calculations. I had checked for NA, but hadn't thought to check for Inf.
I wrote the following function to help prevent this situation in the future:
is.bad <- function(x){
is.na(x) | is.nan(x) | is.infinite(x)
}
> is.bad(c(NA, NaN, Inf, -Inf, 0, 1, 1000, 1e6))
[1] TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE
Are there any other special data types in R I should be aware of?