canCoerce              package:methods              R Documentation

_C_a_n _a_n _O_b_j_e_c_t _b_e _C_o_e_r_c_e_d _t_o _a _C_e_r_t_a_i_n _S_4 _C_l_a_s_s?

_D_e_s_c_r_i_p_t_i_o_n:

     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.

_U_s_a_g_e:

     canCoerce(object, Class)

_A_r_g_u_m_e_n_t_s:

  object: any R object, typically of a formal S4 class.

   Class: an S4 class (see 'isClass').

_V_a_l_u_e:

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

_S_e_e _A_l_s_o:

     'as', 'setAs', 'selectMethod', 'setClass',

_E_x_a_m_p_l_e_s:

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

