asObject {Matrix} | R Documentation |
asObject
assigns a class to an object and returns the object.
prependClass
prepends a class to the set of classes for an
object and returns the object.
asObject(x, cl) prependClass(x, cl)
x |
an object. |
cl |
a character vector of classes. |
asObject
is simply a wrapper for the sequence
class(x) <- cl; x
. Its main use is in constructing the
value that a function will return. It differs from the assignment
class(x) <- cl
in that the assignment returns the class
whereas asObject
returns the object with the class.
prependClass
is a similar function that extends the classes
(if any) of the object and returns the object.
the object x
with the class cl
(or c(cl,
class(x))
for prependClass
).
x <- asObject(3, "myClass") print.default(x) print.default(prependClass(x, "firstClass"))