\HeaderA{attr}{Object Attributes}{attr}
\aliasA{attr<\Rdash}{attr}{attr<.Rdash.}
\keyword{attribute}{attr}
\begin{Description}\relax
Get or set specific attributes of an object.
\end{Description}
\begin{Usage}
\begin{verbatim}
attr(x, which, exact = FALSE)
attr(x, which) <- value
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] an object whose attributes are to be accessed.
\item[\code{which}] a non-empty character string specifying which attribute
is to be accessed.
\item[\code{exact}] logical: should \code{which} be matched exactly?
\item[\code{value}] an object, the new value of the attribute, or \code{NULL}
to remove the attribute.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
These functions provide access to a single attribute of an object.
The replacement form causes the named attribute to take the value
specified (or create a new attribute with the value given).

The extraction function first looks for an exact match to \code{which}
amongst the attributes of \code{x}, then (unless \code{exact = TRUE})
a unique partial match.
(Setting \code{\LinkA{options}{options}(warnPartialMatchAttr=TRUE)} causes
partial matches to give warnings.)

The replacement function only uses exact matches.

Note that some attributes (namely \code{\LinkA{class}{class}},
\code{\LinkA{comment}{comment}}, \code{\LinkA{dim}{dim}}, \code{\LinkA{dimnames}{dimnames}},
\code{\LinkA{names}{names}}, \code{\LinkA{row.names}{row.names}} and
\code{\LinkA{tsp}{tsp}}) are treated specially and have restrictions on
the values which can be set. (Note that this is not true of
\code{\LinkA{levels}{levels}} which should be set for factors via the
\code{levels} replacement function.)

The extractor function allows (and does not match) empty and missing
values of \code{which}: the replacement function does not.

These functions are \LinkA{primitive}{primitive}, so argument names are ignored.
\end{Details}
\begin{Value}
For the extractor, the value of the attribute matched, or \code{NULL}
if no exact match is found and no or more than one partial match is found.
\end{Value}
\begin{References}\relax
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
\emph{The New S Language}.
Wadsworth \& Brooks/Cole.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{attributes}{attributes}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
# create a 2 by 5 matrix
x <- 1:10
attr(x,"dim") <- c(2, 5)
\end{ExampleCode}
\end{Examples}

