The R Project SVN R

Rev

Rev 74519 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
42333 ripley 1
% File src/library/utils/man/count.fields.Rd
68948 ripley 2
% Part of the R package, https://www.R-project.org
74546 maechler 3
% Copyright 1995-2018 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{
74546 maechler 57
fil <- tempfile()
74519 maechler 58
cat("NAME", "1:John", "2:Paul", file = fil, sep = "\n")
59
count.fields(fil, sep = ":")
60
unlink(fil)
49 hornik 61
}
286 maechler 62
\keyword{file}