canCoerce

Can an Object be Coerced to a Certain S4 Class?

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.

Keywords
classes, methods
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 e.g.setAs) for the signature (from = class(object), to = Class).

See Also

as, setAs, selectMethod, setClass,

Aliases
  • canCoerce
Examples
library(methods) # NOT RUN { m <- matrix(pi, 2,3) canCoerce(m, "numeric") # TRUE canCoerce(m, "array") # TRUE # }
Documentation reproduced from package methods, version 3.5.2, License: Part of R 3.5.2

Community examples

Looks like there are no examples yet.