The R Project SVN R

Rev

Rev 61132 | Rev 74519 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
42333 ripley 1
% File src/library/base/man/write.Rd
2
% Part of the R package, http://www.R-project.org
61132 ripley 3
% Copyright 1995-2012 R Core Team
42333 ripley 4
% Distributed under GPL 2 or later
5
 
2 r 6
\name{write}
7081 pd 7
\title{Write Data to a File}
2 r 8
\usage{
9940 pd 9
write(x, file = "data",
10
      ncolumns = if(is.character(x)) 1 else 5,
34349 maechler 11
      append = FALSE, sep = " ")
2 r 12
}
56186 murdoch 13
\alias{write}
2 r 14
\arguments{
61132 ripley 15
  \item{x}{the data to be written out, usually an atomic vector.}
40227 ripley 16
  \item{file}{A connection, or a character string naming the file to write to.
11656 ripley 17
    If \code{""}, print to the standard output connection.
8701 ripley 18
#ifdef unix
19
    If it is \code{"|cmd"}, the output is piped to the command given
20
    by \file{cmd}.
21
#endif
22
  }
23
  \item{ncolumns}{the number of columns to write the data in.}
40227 ripley 24
  \item{append}{if \code{TRUE} the data \code{x} are appended to the
25
    connection.}
34355 maechler 26
  \item{sep}{a string used to separate columns.  Using \code{sep = "\t"}
34349 maechler 27
    gives tab delimited output; default is \code{" "}.}
2 r 28
}
29
\description{
8701 ripley 30
  The data (usually a matrix) \code{x} are written to file \code{file}.
31
  If \code{x} is a two-dimensional matrix you need to transpose it to get the
32
  columns in \code{file} the same as those in the internal representation.
2 r 33
}
24300 ripley 34
\references{
35
  Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
36
  \emph{The New S Language}.
47262 ripley 37
  Wadsworth & Brooks/Cole.
24300 ripley 38
}
2 r 39
\seealso{
40227 ripley 40
  \code{write} is a wrapper for \code{\link{cat}}, which gives further
41
  details on the format used.
61433 ripley 42
 
9940 pd 43
  \code{\link{save}} for writing any \R objects,
44
  \code{\link{write.table}} for data frames,
45
  and \code{\link{scan}} for reading data.
2 r 46
}
47
\examples{
48
# create a 2 by 5 matrix
61132 ripley 49
x <- matrix(1:10, ncol = 5)
2 r 50
 
51
# the file data contains x, two rows, five cols
37666 ripley 52
# 1 3 5 7 9 will form the first row
2 r 53
write(t(x))
54
 
34349 maechler 55
# Writing to the "console" 'tab-delimited'
2 r 56
# two rows, five cols but the first row is 1 2 3 4 5
34349 maechler 57
write(x, "", sep = "\t")
8098 ripley 58
unlink("data") # tidy up
2 r 59
}
286 maechler 60
\keyword{file}
11656 ripley 61
\keyword{connection}