\HeaderA{cbind2}{Combine two Objects by Columns or Rows}{cbind2}
\aliasA{cbind2,ANY,ANY-method}{cbind2}{cbind2,ANY,ANY.Rdash.method}
\aliasA{cbind2,ANY,missing-method}{cbind2}{cbind2,ANY,missing.Rdash.method}
\aliasA{cbind2-methods}{cbind2}{cbind2.Rdash.methods}
\aliasA{rbind2}{cbind2}{rbind2}
\aliasA{rbind2,ANY,ANY-method}{cbind2}{rbind2,ANY,ANY.Rdash.method}
\aliasA{rbind2,ANY,missing-method}{cbind2}{rbind2,ANY,missing.Rdash.method}
\aliasA{rbind2-methods}{cbind2}{rbind2.Rdash.methods}
\keyword{array}{cbind2}
\keyword{manip}{cbind2}
\begin{Description}\relax
Combine two \dQuote{matrix-like} \R{} objects by columns (\code{cbind2})
or rows (\code{rbind2}). These are (S4) generic functions with default
methods.
\end{Description}
\begin{Usage}
\begin{verbatim}
cbind2(x, y)
rbind2(x, y)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] any \R{} object, typically \dQuote{matrix-like}.
\item[\code{y}] any \R{} object, typically similar to \code{x}, or missing
completely.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The main use of \code{cbind2} (\code{rbind2}) is to be called by
\code{\LinkA{cbind}{cbind}()}  (\code{rbind()})
\bold{if} these are activated.  This allows \code{cbind}
(\code{rbind}) to \dQuote{work} for formally classed (aka \sQuote{S4})
objects by providing S4 methods for these objects.  Currently, a call\\
\code{methods:::bind\_activation(TRUE)}\\
is needed to install a
\dQuote{\code{cbind2}-calling} version of \code{cbind} (into the
\code{base} namespace) and the same for \code{rbind}.\\
\code{methods:::bind\_activation(FALSE)} reverts to the
previous internal version of \code{cbind} which does not build on
\code{cbind2}, see the examples.
\end{Details}
\begin{Value}
A matrix (or matrix like object) combining the columns (or rows) of
\code{x} and \code{y}.
\end{Value}
\begin{Section}{Methods}
\describe{
\item[x = "ANY", y = "ANY"] the default method using \R's internal code.
\item[x = "ANY", y = "missing"] the default method for one argument
using \R's internal code.
}
\end{Section}
\begin{SeeAlso}\relax
\code{\LinkA{cbind}{cbind}}, \code{\LinkA{rbind}{rbind}}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
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)
\end{ExampleCode}
\end{Examples}

