\HeaderA{canCoerce}{Can an Object be Coerced to a Certain S4 Class?}{canCoerce}
\keyword{classes}{canCoerce}
\keyword{methods}{canCoerce}
\begin{Description}\relax
Test if an object can be coerced to a given S4 class.
Maybe useful inside \code{if()} to ensure that calling
\code{as(object, Class)} will find a method.
\end{Description}
\begin{Usage}
\begin{verbatim}
canCoerce(object, Class)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{object}] any \R{} object, typically of a formal S4 class.
\item[\code{Class}] an S4 class (see \code{\LinkA{isClass}{isClass}}).
\end{ldescription}
\end{Arguments}
\begin{Value}
a scalar logical, \code{TRUE} if there is a \code{coerce} method
(as defined by \code{\LinkA{setAs}{setAs}}, e.g.) for the signature
\code{(from = class(object), to = Class)}.
\end{Value}
\begin{SeeAlso}\relax
\code{\LinkA{as}{as}}, \code{\LinkA{setAs}{setAs}},
\code{\LinkA{selectMethod}{selectMethod}}, \code{\LinkA{setClass}{setClass}},
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
m <- matrix(pi, 2,3)
canCoerce(m, "numeric") # TRUE
canCoerce(m, "array")   # TRUE
\end{ExampleCode}
\end{Examples}

