R/addClasses.R

Defines functions addClasses

Documented in addClasses

#' A wrapper to add to the class attribute.
#'
#' @param x [any]\cr
#'   Your object.
#' @param classes [\code{character}]\cr
#'  Classes to add. Will be added in front (specialization).
#' @return Changed object \code{x}.
#' @export
#' @examples
#' x = list()
#' print(class(x))
#' x = addClasses(x, c("foo1", "foo2"))
#' print(class(x))
addClasses = function(x, classes) {
  class(x) = c(classes, class(x))
  x
}

Try the BBmisc package in your browser

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

BBmisc documentation built on Sept. 29, 2022, 5:12 p.m.