The R Project SVN R

Rev

Details | Last modification | View Log | RSS feed

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