count_lines: Count the number of lines of a file

Description Usage Arguments Details Value Examples

View source: R/count_lines.R

Description

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).

Usage

1
count_lines(file, ext = NA, verbose = TRUE)

Arguments

file

The input file path to read (a string).

ext

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.

verbose

If TRUE (default), writes a message reporting the file whose lines are being counted (after adding extensions if it was needed).

Details

Note: this function does not work correctly with compressed files (they are not uncompressed prior to counting newlines).

Value

The number of lines in the file.

Examples

1
2
3
4
5
6
7
8
9
# 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

genio documentation built on July 27, 2021, 1:06 a.m.