EVOLUTION-MANAGER
Edit File: attributes.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Object Attribute Lists</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for attributes {base}"><tr><td>attributes {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Object Attribute Lists</h2> <h3>Description</h3> <p>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). </p> <h3>Usage</h3> <pre> attributes(x) attributes(x) <- value mostattributes(x) <- value </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>any <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> object</p> </td></tr> <tr valign="top"><td><code>value</code></td> <td> <p>an appropriate named <code><a href="list.html">list</a></code> of attributes, or <code>NULL</code>.</p> </td></tr> </table> <h3>Details</h3> <p>Unlike <code><a href="attr.html">attr</a></code> it is not an error to set attributes on a <code>NULL</code> object: it will first be coerced to an empty list. </p> <p>Note that some attributes (namely <code><a href="class.html">class</a></code>, <code><a href="comment.html">comment</a></code>, <code><a href="dim.html">dim</a></code>, <code><a href="dimnames.html">dimnames</a></code>, <code><a href="names.html">names</a></code>, <code><a href="row.names.html">row.names</a></code> and <code><a href="../../stats/html/tsp.html">tsp</a></code>) are treated specially and have restrictions on the values which can be set. (Note that this is not true of <code><a href="levels.html">levels</a></code> which should be set for factors via the <code>levels</code> replacement function.) </p> <p>Attributes are not stored internally as a list and should be thought of as a set and not a vector, i.e, the <em>order</em> of the elements of <code>attributes()</code> does not matter. This is also reflected by <code><a href="identical.html">identical</a>()</code>'s behaviour with the default argument <code>attrib.as.set = TRUE</code>. Attributes must have unique names (and <code>NA</code> is taken as <code>"NA"</code>, not a missing value). </p> <p>Assigning attributes first removes all attributes, then sets any <code>dim</code> attribute and then the remaining attributes in the order given: this ensures that setting a <code>dim</code> attribute always precedes the <code>dimnames</code> attribute. </p> <p>The <code>mostattributes</code> assignment takes special care for the <code><a href="dim.html">dim</a></code>, <code><a href="names.html">names</a></code> and <code><a href="dimnames.html">dimnames</a></code> attributes, and assigns them only when known to be valid whereas an <code>attributes</code> 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 <code><a href="row.names.html">row.names</a></code> are assigned correctly for data frames. </p> <p>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 <code>attributes</code>). </p> <p><code><a href="NULL.html">NULL</a></code> objects cannot have attributes and attempts to assign them will promote the object to an empty list. </p> <p>Both assignment and replacement forms of <code>attributes</code> are <a href="Primitive.html">primitive</a> functions. </p> <h3>References</h3> <p>Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) <em>The New S Language</em>. Wadsworth & Brooks/Cole. </p> <h3>See Also</h3> <p><code><a href="attr.html">attr</a></code>, <code><a href="structure.html">structure</a></code>. </p> <h3>Examples</h3> <pre> 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 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 </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>