The R Project SVN R

Rev

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

Rev 13932 Rev 16016
1
\name{count.fields}
1
\name{count.fields}
2
\title{Count the Number of Fields per Line}
2
\title{Count the Number of Fields per Line}
3
\usage{
3
\usage{
4
count.fields(file, sep = "", quote = "\"'", skip = 0,
4
count.fields(file, sep = "", quote = "\"'", skip = 0,
5
             blank.lines.skip = TRUE)
5
             blank.lines.skip = TRUE, comment.char = "#")
6
}
6
}
7
\alias{count.fields}
7
\alias{count.fields}
8
\arguments{
8
\arguments{
9
  \item{file}{a character string naming an ASCII data file, or a
9
  \item{file}{a character string naming an ASCII data file, or a
10
    \code{\link{connection}}, which will be opened if necessary,
10
    \code{\link{connection}}, which will be opened if necessary,
11
    and if so closed at the end of the function call.}
11
    and if so closed at the end of the function call.}
12
 
12
 
13
  \item{sep}{the field separator character.  Values on each line of the
13
  \item{sep}{the field separator character.  Values on each line of the
14
    file are separated by this character.  By default, arbitrary amounts
14
    file are separated by this character.  By default, arbitrary amounts
15
    of whitespace can separate fields.}
15
    of whitespace can separate fields.}
16
 
16
 
17
  \item{quote}{the set of quoting characters}
17
  \item{quote}{the set of quoting characters}
18
 
18
 
19
  \item{skip}{the number of lines of the data file to skip before
19
  \item{skip}{the number of lines of the data file to skip before
20
    beginning to read data.}
20
    beginning to read data.}
21
 
21
 
22
  \item{blank.lines.skip}{logical: if \code{TRUE} blank lines in the
22
  \item{blank.lines.skip}{logical: if \code{TRUE} blank lines in the
23
    input are ignored.}
23
    input are ignored.}
-
 
24
 
-
 
25
  \item{comment.char}{character: a character vector of length one
-
 
26
    containing a single character or an empty string.}
24
}
27
}
25
\description{
28
\description{
26
  \code{count.fields} counts the number of fields, as separated by
29
  \code{count.fields} counts the number of fields, as separated by
27
  \code{sep}, in each of the lines of \code{file} read.
30
  \code{sep}, in each of the lines of \code{file} read.
28
}
31
}
29
\details{
32
\details{
30
  This used to be used by \code{\link{read.table}} and can still be
33
  This used to be used by \code{\link{read.table}} and can still be
31
  useful in discovering problems in reading a file by that function.
34
  useful in discovering problems in reading a file by that function.
-
 
35
 
-
 
36
  For the handling of comments, see \code{\link{scan}}.
32
}
37
}
33
\value{
38
\value{
34
  A vector with the numbers of fields found.
39
  A vector with the numbers of fields found.
35
}
40
}
36
\seealso{
41
\seealso{
37
  \code{\link{read.table}}
42
  \code{\link{read.table}}
38
}
43
}
39
\examples{
44
\examples{
40
cat("NAME", "1:John", "2:Paul", file = "foo", sep = "\n")
45
cat("NAME", "1:John", "2:Paul", file = "foo", sep = "\n")
41
count.fields("foo", sep = ":")
46
count.fields("foo", sep = ":")
42
unlink("foo")
47
unlink("foo")
43
}
48
}
44
\keyword{file}
49
\keyword{file}