% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/class.r
\name{addClass}
\alias{addClass}
\title{Add a Class to an Object}
\usage{
addClass(x, class, prepend = TRUE)
}
\arguments{
\item{x}{an \strong{R} object.}

\item{class}{character vector, or object coercible to character,
of one or more class names to add.}

\item{prepend}{logical. If \code{TRUE} the new class(es) are
prepended to the existing class vector. If \code{FALSE}, the class
vector is replaced entirely.}
}
\value{
The input object \code{x} with its class attribute updated.
}
\description{
Add a class to an object, either appending to, or replacing, the
existing class vector.
}
\details{
With \code{prepend = TRUE}, \code{addClass()} is equivalent to:

\if{html}{\out{<div class="sourceCode r">}}\preformatted{class(x) <- c(class, class(x))
x
}\if{html}{\out{</div>}}

With \code{prepend = FALSE}:

\if{html}{\out{<div class="sourceCode r">}}\preformatted{class(x) <- class
x
}\if{html}{\out{</div>}}
}
\examples{
x <- structure(1, class = "base_class")
y <- addClass(x, c("new_class", "another_class"))
class(y)

y <- addClass(x, c("new_class", "another_class"), prepend = FALSE)
class(y)
}
\seealso{
\link{class}, \link{inherits}, \link{is}.
}
