attr(x, which) attr(x, which) <- value
x
.
which
attribute of
x
, if it exists; otherwise,
NULL
.
The assignment form returns
value
.
x
, and generally the class of
x
, will be changed
as a result of the assignment
version of this function.
If the attribute did not previously exist, the class is usually changed
to
"structure"
,
although some attributes
(for example,
"dim"
and
"levels"
)
result in other classes (such as
"array"
or
"matrix"
, and
"category"
).
names
(a
"names"
attribute) to a matrix or array
currently erases
"dim"
and
"dimnames"
attributes and changes a matrix
or array to a vector or
bdVector
with class
"named"
.
Every data object receives two attributes ("length" and "mode")
simply by being defined. "Length" specifies the number of values in the
object and "mode" returns the type of object (for example,
"bdFrame"
,
"bdNumeric"
, "numeric", "list",
"logical", "NULL"). "Length" and "mode" are implicit attributes.
Other attributes may define various data types in the object ("dim")
or store
labels for data in the object ("dimnames" or "names").
For the attributes like
dim
that are known internally to S-PLUS,
the assignment is accepted only if it satisfies requirements
for that attribute (for example, the length of
x
must equal the
product of the dimensions).
See the documentation for individual attributes.
attr
may also be used to set and get user-defined attributes.
To explicitly delete the
which
attribute of
x
, use
attr(x, which) <- NULL
.
The semantics of
attr
are defined by saying that
attr(x, which)
is equivalent to
attributes(x)[[which]]
for either extracting
or replacing attributes,
with the restriction that
which
is interpreted as mode character.
The value of
attributes(x)
is a list object (possibly of length
0
)
associated implicitly with any object
x
.
See
Subscript
for the semantics of
[[ .
attr(iris, "dimnames") # equivalent to dimnames(iris) # a possible way to store documentation with x attr(x, "doc") <- doc.x