attr {reflections} | R Documentation |
Get or set specific attributes of an object.
attr(x, which,
exact = FALSE,
value = NULL);
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 which amongst the attributes Of x, Then (unless exact = True) a unique Partial match. (Setting options(warnPartialMatchAttr = True) causes Partial matches To give warnings.) The replacement Function only uses exact matches. 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.) The extractor Function allows (And does Not match) empty And missing values Of which: the replacement Function does Not. NULL objects cannot have attributes And attempting To assign one by attr gives an Error. Both are primitive functions.
For the extractor, the value of the attribute matched, or NULL if no exact match is found and no or more than one partial match is found.
# create a 2 by 5 matrix
x <- 110
attr(x,"dim") <- c(2, 5)