as
Generic Coercion Function
Description
Coerces an object from one class to another.
Usage
as(object, Class, strict = TRUE, ext = possibleExtends(thisClass, Class))
setAs(from, to, def, replace = NULL, where = topenv(parent.frame()))
Arguments
object |
an expression evaluating to an object to be coerced.
|
Class |
a character string specifying to which class object
is coerced.
|
strict |
a logical value.
- If TRUE (the default), the returned object must have the specified class.
- If FALSE, and if object is from a subclass
of Class, then object is returned unchanged.
|
ext |
this argument is unimplemented, and a warning is generated if it is given.
|
from, to |
a character string name of the class to be defined.
|
def |
a function object or function with function definition.
The function used for coercing class from to class to.
|
def, replace |
a function object or a function name;
the method for coercing class from to class to.
|
where |
the database on which to look. By default, all the currently-attached chapters are
searched.
|
Details
This is the S4 generic coercion function.
This function coerces the object specified by object by selecting an S4 method for the function
coerce, which should be defined with the arguments
function(from, to, strict=TRUE)) ....
Currently-available coerce methods from one class to another can be
listed by showMethods("coerce").
- The class specified by to should be defined in the where environment.
- The class specified by to cannot be a union class.
- Argument names in the function specified by def should have one argument, or should match the arguments
(c("from", "to", "strict")) of coerce().
- Argument names in replace should agree with coerce<-.
- If replace is not NULL, replace should be a function with the arguments "from", "to", or "value", or
it should be a function with two arguments.
Value
as |
returns the coerced object.
|
setAs |
returns NULL. Creating a generic function for "coerces" coerces the class from to the class to.
|
See Also
Examples
as(1:10, "character")
as(1:12, "complex")
setClass("test1")
setClass("test2")
setAs("test1", "test2", function(from) quote(from))