
This function returns the number of lines in a file.
It is intended to result in fast retrieval of numbers of individuals (from FAM or equivalent files) or loci (BIM or equivalent files) when the input files are extremely large and no other information is required from these files.
This code uses C++ to quickly counts lines (like linux's wc -l
but this one is cross-platform).
count_lines(file, ext = NA, verbose = TRUE)
The number of lines in the file.
The input file path to read (a string).
An optional extension.
If NA
(default), file
is expected to exist as-is.
Otherwise, if file
doesn't exist and the extension was missing, then this extension is added.
If TRUE
(default), writes a message reporting the file whose lines are being counted (after adding extensions if it was needed).
Note: this function does not work correctly with compressed files (they are not uncompressed prior to counting newlines).
# count number of individuals from an existing plink *.fam file
file <- system.file("extdata", 'sample.fam', package = "genio", mustWork = TRUE)
n_ind <- count_lines(file)
n_ind
# count number of loci from an existing plink *.bim file
file <- system.file("extdata", 'sample.bim', package = "genio", mustWork = TRUE)
m_loci <- count_lines(file)
m_loci
Run the code above in your browser using DataLab