\HeaderA{write}{Write Data to a File}{write}
\keyword{file}{write}
\keyword{connection}{write}
\begin{Description}\relax
The data (usually a matrix) \code{x} are written to file \code{file}.
If \code{x} is a two-dimensional matrix you need to transpose it to get the
columns in \code{file} the same as those in the internal representation.
\end{Description}
\begin{Usage}
\begin{verbatim}
write(x, file = "data",
      ncolumns = if(is.character(x)) 1 else 5,
      append = FALSE, sep = " ")
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] the data to be written out.
\item[\code{file}] A connection, or  a character string naming the file to write to.
If \code{""}, print to the standard output connection.
If it is \code{"|cmd"}, the output is piped to the command given
by \file{cmd}.

\item[\code{ncolumns}] the number of columns to write the data in.
\item[\code{append}] if \code{TRUE} the data \code{x} is appended to file \code{file}.
\item[\code{sep}] a string used to separate columns.  Using \code{sep = "\\t"}
gives tab delimited output; default is \code{" "}.
\end{ldescription}
\end{Arguments}
\begin{References}\relax
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
\emph{The New S Language}.
Wadsworth \& Brooks/Cole.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{save}{save}} for writing any \R{} objects,
\code{\LinkA{write.table}{write.table}} for data frames,
and \code{\LinkA{scan}{scan}} for reading data.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
# create a 2 by 5 matrix
x <- matrix(1:10,ncol=5)

# the file data contains x, two rows, five cols
# 1 3 5 6 9 will form the first row
write(t(x))

# Writing to the "console" 'tab-delimited'
# two rows, five cols but the first row is 1 2 3 4 5
write(x, "", sep = "\t")
unlink("data") # tidy up
\end{ExampleCode}
\end{Examples}

