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)