attributes               package:base               R Documentation

_O_b_j_e_c_t _A_t_t_r_i_b_u_t_e _L_i_s_t_s

_D_e_s_c_r_i_p_t_i_o_n:

     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).

_U_s_a_g_e:

     attributes(obj)
     attributes(obj) <- value
     mostattributes(obj) <- value

_A_r_g_u_m_e_n_t_s:

     obj: an object

   value: an appropriate named list of attributes, or 'NULL'.

_D_e_t_a_i_l_s:

     Unlike 'attr' it is possible to set attributes on a 'NULL' object:
     it will first be coerced to an empty list.

     Note that some attributes (namely 'class', 'comment', 'dim',
     'dimnames', 'names', 'row.names' and 'tsp') are treated specially
     and have restrictions on the values which can be set.  (Note that
     this is not true of 'levels' 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.  They 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',
     'names' and 'dimnames' attributes, and assigns them only when
     valid whereas an 'attributes' assignment would give an error if
     any are not.

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

_R_e_f_e_r_e_n_c_e_s:

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

_S_e_e _A_l_s_o:

     'attr'.

_E_x_a_m_p_l_e_s:

     x <- cbind(a=1:3, pi=pi) # simple matrix w/ dimnames
     attributes(x)

     ## strip an object's attributes:
     attributes(x) <- NULL
     x # now just a vector of length 6

     mostattributes(x) <- list(mycomment = "really special", dim = 3:2,
        dimnames = list(LETTERS[1:3], letters[1:5]), names = paste(1:6))
     x # dim(), but not {dim}names

