Learn R Programming

Copy Link

Version

Install

install.packages('pgenlibr')

Monthly Downloads

1,100

Version

0.7.0

License

LGPL (>= 3)

Maintainer

Christopher Chang

Last Published

September 30th, 2026

Functions in pgenlibr (0.7.0)

ClosePgen

Closes a pgen object, releasing resources.
GetVariantCt

Returns the number of variants in the file.
GetWrittenVariantCt

Returns the number of variants appended so far to a .pgen being written.
GetRawSampleCt

Returns the number of samples in the file.
GetVariantChrom

Retrieve chromosome ID for given variant index.
GetVariantPos

Retrieve POS (base-pair coordinate on a chromosome) for given variant index.
GetMaxAlleleCt

Returns the maximum GetAlleleCt() value across all variants in the file.
GetAlleleCt

Returns the effective number of alleles for a variant. Note that if no pvar was provided to the NewPgen() call, this function may return 2 even at multiallelic variants, since the .pgen may not store allele-count information.
GetVariantId

Convert variant index to variant ID string.
AppendDosages

Appends a biallelic dosage variant to a .pgen being written.
HardcallPhasePresent

Returns whether explicitly phased hardcalls are present.
GetVariantsById

Convert variant ID string to variant index(es).
IntAlleleCodeBuf

Returns an empty two-row integer matrix that ReadAlleles() can load to.
IntBuf

Returns an integer buffer that ReadHardcalls() can load to.
ReadHardcalls

Loads the variant_numth variant, and then fills buf with {0, 1, 2, NA} values indicating the number of copies of the first ALT (or user-specified) allele each sample has.
Read

Loads the variant_numth variant, and then fills buf with numeric dosages in [0, 2] indicating the dosages of the first ALT (or user-specified) allele for each sample, with missing values represented by NA.
HasSparse

Returns whether dosages for the variant_numth variant and given allele are represented in a sparse manner that is supported by ReadSparse(), under the current sample subset.
NewPgen

Opens a .pgen or PLINK 1 .bed file.
HasSparseHardcalls

Returns whether hardcalls for the variant_numth variant and given allele are represented in a sparse manner that is supported by ReadSparseHardcalls().
NewPgenWriter

Creates a new .pgen file for writing.
ReadAlleles

Loads the variant_numth variant, and then fills acbuf with integer allele codes, where each column of the buffer corresponds to a sample. An allele code of 0 corresponds to the REF allele, 1 to the first ALT, 2 to the second ALT, etc. Missing hardcalls are represented by a pair of NA codes.
NewPvar

Loads variant positions, IDs, and allele codes from a .pvar or .bim file (which can be compressed with gzip or Zstd).
ReadIntList

Load hardcalls for multiple variants as an integer matrix.
ReadSparse

If HasSparse() is true, returns a sparse representation for the (variant, allele) pair. If HasSparse() is false, the function fails.
ReadList

Load dosages for multiple variants as a numeric matrix.
VariantScores

Compute variant scores.
ReadSparseHardcalls

If HasSparseHardcalls() is true, returns a sparse representation for the (variant, allele) pair. If HasSparseHardcalls() is false, the function fails.
pgenlibr-package

PLINK 2 Binary (.pgen) Reader
BoolBuf

Returns a bool buffer that ReadAlleles() can load phasing information to.
AlleleCodeBuf

Returns an empty two-row numeric matrix that ReadAlleles() can load to.
Buf

Returns a numeric buffer that Read() or ReadHardcalls() can load to.
ClosePgenWriter

Finalizes a .pgen being written, and releases resources. This must be called after all variant_ct variants have been appended; the .pgen is not valid before then.
AppendBiallelic

Appends an unphased biallelic hardcall variant to a .pgen being written.
GetAlleleCode

Look up an allele code.
ClosePvar

Closes a pvar object, releasing memory.
AppendAlleles

Appends a hardcall variant, specified as allele codes, to a .pgen being written. Unlike AppendBiallelic(), this supports phased and multiallelic hardcalls.