R/otype.R

#' Determine the type of an object
#'
#' Tells you if you're dealing with an base, S3, S4, RC, or R6 object.
#'
#' @param x An object
#' @export
#' @examples
#' otype(1:10)
#' otype(mtcars)
otype <- function(x) {
  if (!is.object(x)) {
    "base"
  } else if (!isS4(x)) {
    if (!inherits(x, "R6")) {
      "S3"
    } else {
      "R6"
    }
  } else {
    if (!is(x, "refClass")) {
      "S4"
    } else {
      "RC"
    }
  }
}

Try the sloop package in your browser

Any scripts or data that you put into this service are public.

sloop documentation built on May 1, 2019, 10:30 p.m.