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

