Remove part of a class attribute


An R object may have a class attribute that is a character vector giving the names of classes it inherits from. stripClass strips the class classString from that character vector. stripTis(x) is shorthand for stripClass(x, "tis").


stripClass(x, classString)



an object whose class character vector may or may not include classString


name of class to remove from the inheritance chain


An object like x, but whose class attribute does not include classString. If the class attribute less classString is empty, unclass(x) is returned.


This function can be useful in functions that return a modified version of one their arguments. For example, the format.ti method takes a ti (TimeIndex) as an argument and returns a character object object 'like' the original argument. The first thing format.ti(x) does internally is z <- stripClass(x, "ti"). This creates z as a copy of x but with the difference that z no longer inherits from class ti. The function then fills in the data elements of z with the approriate strings and returns it. The beauty of this approach is that the returned z already has all of the attributes x had, except that it no longer inherits from class ti. In particular, if x was a matrix with dimnames, etc., z will also have those attributes.

See Also


Want to suggest features or report bugs for Use the GitHub issue tracker. Vote for new features on Trello.

comments powered by Disqus