[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  attributes: Object Attribute Lists

##  Description

These functions access an object's attributes. The first form below returns
the object's attribute list. The replacement forms uses the list on the right-
hand side of the assignment as the object's attributes (if appropriate).

##  Usage

    
    
    attributes(x)
    attributes(x) <- value
    mostattributes(x) <- value

##  Arguments

x

any  R  object

value

an appropriate named ` [ list ](/link/list?package=base&version=3.6.2) ` of
attributes, or ` NULL ` .

##  Details

Unlike ` [ attr ](/link/attr?package=base&version=3.6.2) ` it is not an error
to set attributes on a ` NULL ` object: it will first be coerced to an empty
list.

Note that some attributes (namely ` [ class
](/link/class?package=base&version=3.6.2) ` , ` [ comment
](/link/comment?package=base&version=3.6.2) ` , ` [ dim
](/link/dim?package=base&version=3.6.2) ` , ` [ dimnames
](/link/dimnames?package=base&version=3.6.2) ` , ` [ names
](/link/names?package=base&version=3.6.2) ` , ` [ row.names
](/link/row.names?package=base&version=3.6.2) ` and ` [ tsp
](/link/tsp?package=base&version=3.6.2) ` ) are treated specially and have
restrictions on the values which can be set. (Note that this is not true of `
[ levels ](/link/levels?package=base&version=3.6.2) ` which should be set for
factors via the ` levels ` replacement function.)

Attributes are not stored internally as a list and should be thought of as a
set and not a vector, i.e, the _order_ of the elements of ` attributes() `
does not matter. This is also reflected by ` [ identical
](/link/identical?package=base&version=3.6.2) () ` 's behaviour with the
default argument ` attrib.as.set = TRUE ` . Attributes must have unique names
(and ` NA ` is taken as ` "NA" ` , not a missing value).

Assigning attributes first removes all attributes, then sets any ` dim `
attribute and then the remaining attributes in the order given: this ensures
that setting a ` dim ` attribute always precedes the ` dimnames ` attribute.

The ` mostattributes ` assignment takes special care for the ` [ dim
](/link/dim?package=base&version=3.6.2) ` , ` [ names
](/link/names?package=base&version=3.6.2) ` and ` [ dimnames
](/link/dimnames?package=base&version=3.6.2) ` attributes, and assigns them
only when known to be valid whereas an ` attributes ` assignment would give an
error if any are not. It is principally intended for arrays, and should be
used with care on classed objects. For example, it does not check that ` [
row.names ](/link/row.names?package=base&version=3.6.2) ` are assigned
correctly for data frames.

The names of a pairlist are not stored as attributes, but are reported as if
they were (and can be set by the replacement form of ` attributes ` ).

` [ NULL ](/link/NULL?package=base&version=3.6.2) ` objects cannot have
attributes and attempts to assign them will promote the object to an empty
list.

Both assignment and replacement forms of ` attributes ` are [ primitive
](/link/primitive?package=base&version=3.6.2) functions.

##  References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S Language_ .
Wadsworth & Brooks/Cole.

##  See Also

` [ attr ](/link/attr?package=base&version=3.6.2) ` , ` [ structure
](/link/structure?package=base&version=3.6.2) ` .

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fattributes&utm_source=r-docs&utm_medium=docs&utm_term=attributes&utm_content=run_example_in_workspace)

    
    
    # NOT RUN {
    x <- cbind(a = 1:3, pi = pi) # simple matrix with dimnames
    attributes(x)
    
    ## strip an object's attributes:
    attributes(x) <- NULL
    x # now just a vector of length 6
    
    mostattrib