Attribute handling
Description
The bc.
functions and the overloaded operators generally do not preserve attributes, unlike the base ‘R’ operators.
Broadcasting often results in an object with more dimensions, larger dimensions, and/or larger length than the original objects.
Therefore, the names
, dimnames
, and dim
attributes often no longer fit the new object.
Moreover, some classes are only appropriate for certain dimensions or lengths.
Custom matrix classes, for example, presumes an object to have exactly 2 dimensions.
And the various classes provided by the ‘bit’ package have length-related attributes.
So even class attributes cannot be guaranteed to hold for the resulting objects.
However, the bc.
functions and the overloaded operators always preserve the "broadcaster" attribute, as this is necessary to chain together broadcasted operations.
Notice that this contrats with base ‘R’ in the following sense:
In base ‘R’, logical (&, |) and relational (==, !=, etc.) operators never preserve attributes, whereas the broadcasted equivalents do preserve the "broadcaster" attribute.
Almost all functions provided by ‘broadcast’ are S3 or S4 generics;
methods can be written for them for specific classes, so that class-specific attributes can be supported when needed.
Unary operations (i.e. + x
, - x
) return the original object, with only the sign adjusted.