1% File src/library/utils/man/count.fields.Rd
2% Part of the R package, https://www.R-project.org
3% Copyright 1995-2018 R Core Team
4% Distributed under GPL 2 or later
5
6\name{count.fields}
7\title{Count the Number of Fields per Line}
8\usage{
9count.fields(file, sep = "", quote = "\"'", skip = 0,
10             blank.lines.skip = TRUE, comment.char = "#")
11}
12\alias{count.fields}
13\arguments{
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.}
17
18  \item{sep}{the field separator character.  Values on each line of the
19    file are separated by this character.  By default, arbitrary amounts
20    of whitespace can separate fields.}
21
22  \item{quote}{the set of quoting characters}
23
24  \item{skip}{the number of lines of the data file to skip before
25    beginning to read data.}
26
27  \item{blank.lines.skip}{logical: if \code{TRUE} blank lines in the
28    input are ignored.}
29
30  \item{comment.char}{character: a character vector of length one
31    containing a single character or an empty string.}
32}
33\description{
34  \code{count.fields} counts the number of fields, as separated by
35  \code{sep}, in each of the lines of \code{file} read.
36}
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.
40
41  For the handling of comments, see \code{\link{scan}}.
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
49}
50\value{
51  A vector with the numbers of fields found.
52}
53\seealso{
54  \code{\link{read.table}}
55}
56\examples{
57fil <- tempfile()
58cat("NAME", "1:John", "2:Paul", file = fil, sep = "\n")
59count.fields(fil, sep = ":")
60unlink(fil)
61}
62\keyword{file}
63