Skip to content

Instantly share code, notes, and snippets.

@jokergoo
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jokergoo/4f21b81da6f5486ec206 to your computer and use it in GitHub Desktop.
Save jokergoo/4f21b81da6f5486ec206 to your computer and use it in GitHub Desktop.
is_abs_unit <- function(x) UseMethod("is_abs_unit")
is_abs_unit.unit = function(x) {
unit = attr(x, "valid.unit")
if(unit %in% c(1:4, 7:24)) {
return(TRUE)
} else {
return(FALSE)
}
}
is_abs_unit.unit.list = function(x) {
all(sapply(x, is_abs_unit))
}
is_abs_unit.unit.arithmetic = function(x) {
nm = names(x)
all(sapply(x, function(y) {
if(is.character(y)) TRUE
else if(is.null(y)) TRUE
else is_abs_unit(y)
}))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment