count.fields
Count the Number of Fields per Line

Description

Scan an ASCII text file and count the number of fields on each line.

Usage

count.fields(file, sep = "", quote = "\"'", skip = 0, blank.lines.skip = TRUE, 
    comment.char = "#", nmax = -1, skipNul = FALSE)

Arguments

file the name of the text file of ASCII data. The file should contain one line per row of the table, with fields separated by the character in sep. It should be a character string or connection.
sep a single-character field separator, often "\t" for tabs or "\n" for newlines. If omitted, any amount of white space (blanks, tabs, and possibly newlines) can separate fields. By default, sep="".
skip the number of initial lines of the file to skip prior to reading. By default, skip=0, and reading begins at the top of the file.
blank.lines.skip a logical value. If TRUE (the default), blank lines are omitted, except when counting skip.
comment.char a character vector of length one. Contains one single character or an empty string. "" disables the interpretation of comments altogether. The default value is "#".
nmax an integer to specify the maximum number of records to be read. If nmax is not provided, not positive, or not valid, then count.fields reads to the end of file.
skipNul A logical value telling how to deal with nul (0) bytes in the input file. If FALSE then count.fields will warn about nul bytes and will probably return inappropriate results. If TRUE then the nul bytes will be omitted. If the input character encoding is one that normally includes nul bytes (such as UTF-16), this value is ignored, and these bytes will not be skipped.
Value
returns a vector giving the number fields, in the sense of scan or read.table, on each line of the file.
Differences between Spotfire Enterprise Runtime for R and Open-source R
Open-source R does not have the nmax argument.
See Also
scan, read.table.
Examples
cat("user", "1:id:name", "2:id:name", "#2:id:name", file="foo", sep = "\n")
count.fields("foo", sep = ":")
unlink("foo")
# [1] 1 3 3

Package utils version 6.1.4-13
Package Index