file.ncol: Find the number of columns (lines) in a file.

Description Usage Arguments Value Author(s) See Also Examples

View source: R/reader.R

Description

Returns the number of columns in a datafile. File equivalent of ncol()

Usage

1
2
file.ncol(fn, reader = FALSE, del = NULL, comment = "#", skip = 0,
  force = FALSE, excl.rn = FALSE)

Arguments

fn

name of the file(s) to get the length of

reader

try to read the entire file to get a result, else looks at the top few lines (ignoring comments)

del

specify a delimiter (else this will be auto-detected)

comment

a comment symbol to ignore lines in files

skip

number of lines to skip at top of file before processing

force

try to read the file regardless of whether it looks like an invalid file type. Only use when you know the files are valid

excl.rn

exclude rownames from column count (essentially subtract 1)

Value

returns number of columns in file(s). If no delimiter, then =1

Author(s)

Nicholas Cooper nick.cooper@cimr.cam.ac.uk

See Also

file.nrow

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
orig.dir <- getwd(); setwd(tempdir()); # move to temporary dir
write.table(matrix(rnorm(100),nrow=10),"temp.txt",col.names=FALSE,row.names=FALSE)
file.ncol("temp.txt",excl.rn=TRUE)
unlink("temp.txt")
# find ncol for all files in current directory:
# [NB: use with caution, will be slow if dir contains large files]
# not run # lf <- list.files(); if(length(lf)==0) { print("no files in dir") }
# lf <- lf[classify.ext(lf)=="TXT"]
# not run (only works if length(lf)>0) # file.ncol(lf) 
setwd(orig.dir) # reset working directory to original

reader documentation built on May 2, 2019, 9:27 a.m.