Skip to content

Instantly share code, notes, and snippets.

@twolodzko
Last active September 27, 2017 09:33
Show Gist options
  • Save twolodzko/d27dcf0a698eb03fadb7b02b9ea7a846 to your computer and use it in GitHub Desktop.
Save twolodzko/d27dcf0a698eb03fadb7b02b9ea7a846 to your computer and use it in GitHub Desktop.
lst <- function(...) {
dots <- list(...)
call <- match.call()
names(dots) <- sapply(substitute(...()), as.character)
dots
}
funs <- lst(mode, typeof, class, is.atomic, is.array, is.vector, is.numeric, is.character, is.logical, is.matrix, is.data.frame, is.list)
tests <- lst(
NULL,
NA,
NaN,
NA_real_,
NA_character_,
c(),
vector(),
numeric(),
character(),
factor(),
array(),
matrix(),
list(),
data.frame(),
ts()
)
out <- as.data.frame(matrix(NA_integer_, length(tests), length(funs)))
nams <- names(tests)
nams[c(1, 2, 4, 5)] <- c("NULL", "NA", "NA_real_", "NA_character_")
colnames(out) <- names(funs)
rownames(out) <- nams
for (i in seq_along(funs)) {
for (j in seq_along(tests)) {
out[j, i] <- funs[[i]](tests[[j]])
}
}
for (i in 4:ncol(out))
out[, i] <- as.logical(out[, i])
out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment