Learn R Programming

reader (version 1.1.0)

file.nrow: Find the number of rows (lines) in a file.

Description

Returns the number of lines in a file, which in the case of a datafile will often correspond to the number of rows, or rows+1. Can also do this for all files in the directory. File equivalent of nrow()

Usage

file.nrow(fn = "", dir = "", all.in.dir = FALSE)

Value

returns length of file (or all files)

Arguments

fn

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

dir

optional path for fn location, or specify all files in dir

all.in.dir

select whether to extract length for all files in dir

Author

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

See Also

file.ncol

Examples

Run this code
orig.dir <- getwd(); setwd(tempdir()); # move to temporary dir
write.table(matrix(rnorm(100),nrow=10),"temp.txt",col.names=FALSE)
file.nrow("temp.txt")
# use with caution, will be slow if dir contains large files
# not run # file.nrow(all.in.dir=TRUE) 
unlink("temp.txt")
setwd(orig.dir) # reset working directory to original

Run the code above in your browser using DataLab