cbind2                package:methods                R Documentation

_C_o_m_b_i_n_e _t_w_o _O_b_j_e_c_t_s _b_y _C_o_l_u_m_n_s _o_r _R_o_w_s

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

     Combine two matrix-like R objects by columns ('cbind2') or rows
     ('rbind2'). These are (S4) generic functions with default methods.

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

     cbind2(x, y)
     rbind2(x, y)

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

       x: any R object, typically matrix-like.

       y: any R object, typically similar to 'x', or missing
          completely.

_D_e_t_a_i_l_s:

     The main use of 'cbind2' ('rbind2') is to be called by 'cbind()' 
     ('rbind()') *if* these are activated.  This allows 'cbind'
     ('rbind') to work for formally classed (aka 'S4') objects by
     providing S4 methods for these objects.  Currently, a call
      'methods:::bind_activation(TRUE)'
      is needed to install a 'cbind2'-calling version of 'cbind' (into
     the 'base' name space) and the same for 'rbind'.
      'methods:::bind_activation(FALSE)' reverts to the previous
     internal version of 'cbind' which does not build on 'cbind2', see
     the examples.

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

     A matrix (or matrix like object) combining the columns (or rows)
     of 'x' and 'y'.

_M_e_t_h_o_d_s:


     _x = "_A_N_Y", _y = "_A_N_Y" the default method using R's internal code.

     _x = "_A_N_Y", _y = "_m_i_s_s_i_n_g" the default method for one argument using
          R's internal code.

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

     'cbind', 'rbind'.

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

     cbind2(1:3, 4)
     m <- matrix(3:8, 2,3, dimnames=list(c("a","b"), LETTERS[1:3]))
     cbind2(1:2, m) # keeps dimnames from m

     ### Note: Use the following activation if you want cbind() to work
     ### ----  on S4 objects -- be careful otherwise!

     methods:::bind_activation(on = TRUE)
     trace("cbind2")
     cbind(a=1:3)# no call to cbind2()
     cbind(a=1:3, four=4, 7:9)# calling cbind2() twice
     untrace("cbind2")



     ## The following fails currently,
     ## since cbind() works recursively from the tail:
     try( cbind(m, a=1, b=3) )

     ## turn off the `special cbind()' :
     methods:::bind_activation(FALSE)

