The R Project SVN R

Rev

Rev 25118 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 25118 Rev 27041
1
\name{write.table}
1
\name{write.table}
2
\alias{write.table}
2
\alias{write.table}
3
\title{Data Output}
3
\title{Data Output}
4
\description{
4
\description{
5
  \code{write.table} prints its required argument \code{x} (after
5
  \code{write.table} prints its required argument \code{x} (after
6
  converting it to a data frame if it is not one already) to
6
  converting it to a data frame if it is not one already) to
7
  \code{file}.  The entries in each line (row) are separated by the
7
  \code{file}.  The entries in each line (row) are separated by the
8
  value of \code{sep}.
8
  value of \code{sep}.
9
}
9
}
10
\usage{
10
\usage{
11
write.table(x, file = "", append = FALSE, quote = TRUE, sep = " ",
11
write.table(x, file = "", append = FALSE, quote = TRUE, sep = " ",
12
            eol = "\n", na = "NA", dec = ".", row.names = TRUE,
12
            eol = "\n", na = "NA", dec = ".", row.names = TRUE,
13
	    col.names = TRUE, qmethod = c("escape", "double"))
13
	    col.names = TRUE, qmethod = c("escape", "double"))
14
}
14
}
15
\arguments{
15
\arguments{
16
  \item{x}{the object to be written, typically a data frame.  If not, it
16
  \item{x}{the object to be written, typically a data frame.  If not, it
17
    is attempted to coerce \code{x} to a data frame.}
17
    is attempted to coerce \code{x} to a data frame.}
18
  \item{file}{either a character string naming a file or a connection.
18
  \item{file}{either a character string naming a file or a connection.
19
    \code{""} indicates output to the console.}
19
    \code{""} indicates output to the console.}
20
  \item{append}{logical.  If \code{TRUE}, the output is appended to the
20
  \item{append}{logical.  If \code{TRUE}, the output is appended to the
21
    file.  If \code{FALSE}, any existing file of the name is destroyed.}
21
    file.  If \code{FALSE}, any existing file of the name is destroyed.}
22
  \item{quote}{a logical or a numeric vector.  If \code{TRUE}, any
22
  \item{quote}{a logical value or a numeric vector.  If \code{TRUE}, any
23
    character or factor columns will be surrounded by double quotes.  If
23
    character or factor columns will be surrounded by double quotes.  If
24
    a numeric vector, its elements are taken as the indices of the
24
    a numeric vector, its elements are taken as the indices of the
25
    variable (columns) to quote.  In both cases, row and columns names
25
    columns to quote.  In both cases, row and column names
26
    are quoted if they are written, but not if \code{quote is FALSE}.} 
26
    are quoted if they are written. If \code{FALSE}, nothing is quoted.}
27
  \item{sep}{the field separator string.  Values within each row of
27
  \item{sep}{the field separator string.  Values within each row of
28
    \code{x} are separated by this string.}
28
    \code{x} are separated by this string.}
29
  \item{eol}{the character(s) to print at the end of each line (row).}
29
  \item{eol}{the character(s) to print at the end of each line (row).}
30
  \item{na}{the string to use for missing values in the data.}
30
  \item{na}{the string to use for missing values in the data.}
31
  \item{dec}{the string to use for decimal points.}
31
  \item{dec}{the string to use for decimal points.}
32
  \item{row.names}{either a logical value indicating whether the row
32
  \item{row.names}{either a logical value indicating whether the row
33
    names of \code{x} are to be written along with \code{x}, or a
33
    names of \code{x} are to be written along with \code{x}, or a
34
    character vector of row names to be written.}
34
    character vector of row names to be written.}
35
  \item{col.names}{either a logical value indicating whether the column
35
  \item{col.names}{either a logical value indicating whether the column
36
    names of \code{x} are to be written along with \code{x}, or a
36
    names of \code{x} are to be written along with \code{x}, or a
37
    character vector of column names to be written.}
37
    character vector of column names to be written.}
38
  \item{qmethod}{a character string specifying how to deal with embedded
38
  \item{qmethod}{a character string specifying how to deal with embedded
39
    double quote characters when quoting strings.  Must be one of
39
    double quote characters when quoting strings.  Must be one of
40
    \code{"escape"} (default), in which case the quote character is
40
    \code{"escape"} (default), in which case the quote character is
41
    escaped in C style by a backslash, or \code{"double"}, in which case
41
    escaped in C style by a backslash, or \code{"double"}, in which case
42
    it is doubled.  You can specify just the initial letter.}
42
    it is doubled.  You can specify just the initial letter.}
43
}
43
}
44
\details{
44
\details{
45
  Normally there is no column name for a column of row names.  If
45
  Normally there is no column name for a column of row names.  If
46
  \code{col.names=NA} a blank column name is added.  This can be used to
46
  \code{col.names=NA} a blank column name is added.  This can be used to
47
  write CSV files for input to spreadsheets.
47
  write CSV files for input to spreadsheets.
48
 
48
 
49
  \code{write.table} can be slow for data frames with large numbers
49
  \code{write.table} can be slow for data frames with large numbers
50
  (hundreds or more) of columns: this is inevitable as each column could
50
  (hundreds or more) of columns: this is inevitable as each column could
51
  be of a different class and so must be handled separately.
51
  be of a different class and so must be handled separately.
52
  Function \code{\link[MASS]{write.matrix}} in package \pkg{MASS}
52
  Function \code{\link[MASS]{write.matrix}} in package \pkg{MASS}
53
  may be much more efficient if \code{x} is a matrix or can be
53
  may be much more efficient if \code{x} is a matrix or can be
54
  represented in a numeric matrix.
54
  represented in a numeric matrix.
55
}
55
}
56
 
56
 
57
\seealso{
57
\seealso{
58
  The \dQuote{R Data Import/Export} manual.
58
  The \dQuote{R Data Import/Export} manual.
59
  
59
  
60
  \code{\link{read.table}}, \code{\link{write}}.
60
  \code{\link{read.table}}, \code{\link{write}}.
61
 
61
 
62
  \code{\link[MASS]{write.matrix}}.
62
  \code{\link[MASS]{write.matrix}}.
63
}
63
}
64
 
64
 
65
\examples{
65
\examples{
66
\dontrun{
66
\dontrun{
67
## To write a CSV file for input to Excel one might use
67
## To write a CSV file for input to Excel one might use
68
write.table(x, file = "foo.csv", sep = ",", col.names = NA)
68
write.table(x, file = "foo.csv", sep = ",", col.names = NA)
69
## and to read this file back into R one needs
69
## and to read this file back into R one needs
70
read.table("file.csv", header = TRUE, sep = ",", row.names=1)
70
read.table("file.csv", header = TRUE, sep = ",", row.names=1)
71
}}
71
}}
72
\keyword{print}
72
\keyword{print}
73
\keyword{file}
73
\keyword{file}