Description Usage Arguments Value Author(s) See Also Examples
Returns the number of columns in a datafile. File equivalent of ncol()
1 2 |
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) |
returns number of columns in file(s). If no delimiter, then =1
Nicholas Cooper nick.cooper@cimr.cam.ac.uk
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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.