| 42333 |
ripley |
1 |
% File src/library/utils/man/count.fields.Rd
|
|
|
2 |
% Part of the R package, http://www.R-project.org
|
| 62511 |
murdoch |
3 |
% Copyright 1995-2013 R Core Team
|
| 42333 |
ripley |
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
| 49 |
hornik |
6 |
\name{count.fields}
|
|
|
7 |
\title{Count the Number of Fields per Line}
|
|
|
8 |
\usage{
|
| 11287 |
ripley |
9 |
count.fields(file, sep = "", quote = "\"'", skip = 0,
|
| 16016 |
ripley |
10 |
blank.lines.skip = TRUE, comment.char = "#")
|
| 49 |
hornik |
11 |
}
|
| 56186 |
murdoch |
12 |
\alias{count.fields}
|
| 49 |
hornik |
13 |
\arguments{
|
| 13932 |
ripley |
14 |
\item{file}{a character string naming an ASCII data file, or a
|
|
|
15 |
\code{\link{connection}}, which will be opened if necessary,
|
|
|
16 |
and if so closed at the end of the function call.}
|
| 11287 |
ripley |
17 |
|
| 49 |
hornik |
18 |
\item{sep}{the field separator character. Values on each line of the
|
|
|
19 |
file are separated by this character. By default, arbitrary amounts
|
| 6994 |
pd |
20 |
of whitespace can separate fields.}
|
| 11287 |
ripley |
21 |
|
| 7895 |
pd |
22 |
\item{quote}{the set of quoting characters}
|
| 11287 |
ripley |
23 |
|
| 49 |
hornik |
24 |
\item{skip}{the number of lines of the data file to skip before
|
|
|
25 |
beginning to read data.}
|
| 11287 |
ripley |
26 |
|
|
|
27 |
\item{blank.lines.skip}{logical: if \code{TRUE} blank lines in the
|
|
|
28 |
input are ignored.}
|
| 16016 |
ripley |
29 |
|
|
|
30 |
\item{comment.char}{character: a character vector of length one
|
|
|
31 |
containing a single character or an empty string.}
|
| 49 |
hornik |
32 |
}
|
|
|
33 |
\description{
|
| 6994 |
pd |
34 |
\code{count.fields} counts the number of fields, as separated by
|
| 13932 |
ripley |
35 |
\code{sep}, in each of the lines of \code{file} read.
|
| 49 |
hornik |
36 |
}
|
| 13932 |
ripley |
37 |
\details{
|
|
|
38 |
This used to be used by \code{\link{read.table}} and can still be
|
|
|
39 |
useful in discovering problems in reading a file by that function.
|
| 16016 |
ripley |
40 |
|
|
|
41 |
For the handling of comments, see \code{\link{scan}}.
|
| 62511 |
murdoch |
42 |
|
|
|
43 |
Consistent with \code{\link{scan}}, \code{count.fields} allows
|
|
|
44 |
quoted strings to contain newline characters. In such a case the
|
|
|
45 |
starting line will have the field count recorded as \code{NA}, and
|
|
|
46 |
the ending line will include the count of all fields from the
|
|
|
47 |
beginning of the record.
|
|
|
48 |
|
| 13932 |
ripley |
49 |
}
|
| 49 |
hornik |
50 |
\value{
|
|
|
51 |
A vector with the numbers of fields found.
|
|
|
52 |
}
|
|
|
53 |
\seealso{
|
|
|
54 |
\code{\link{read.table}}
|
|
|
55 |
}
|
|
|
56 |
\examples{
|
|
|
57 |
cat("NAME", "1:John", "2:Paul", file = "foo", sep = "\n")
|
|
|
58 |
count.fields("foo", sep = ":")
|
| 8098 |
ripley |
59 |
unlink("foo")
|
| 49 |
hornik |
60 |
}
|
| 286 |
maechler |
61 |
\keyword{file}
|