This help topic is for R version 2.9.0. For the current version of R, try https://stat.ethz.ch/R-manual/R-patched/library/methods/html/canCoerce.html
canCoerce {methods}R Documentation

Can an Object be Coerced to a Certain S4 Class?

Description

Test if an object can be coerced to a given S4 class. Maybe useful inside if() to ensure that calling as(object, Class) will find a method.

Usage

canCoerce(object, Class)

Arguments

object

any R object, typically of a formal S4 class.

Class

an S4 class (see isClass).

Value

a scalar logical, TRUE if there is a coerce method (as defined by setAs, e.g.) for the signature (from = class(object), to = Class).

See Also

as, setAs, selectMethod, setClass,

Examples

m <- matrix(pi, 2,3)
canCoerce(m, "numeric") # TRUE
canCoerce(m, "array")   # TRUE


[Package methods version 2.9.0 ]