Extract Genotypes from a PLINK .bed File

A matrix-like data structure that allows for efficient, convenient, and scalable subsetting of binary genotype/phenotype files generated by PLINK (< https://www.cog-genomics.org/plink2>), the whole genome association analysis toolset, without loading the entire file into memory.

BEDMatrix is an R package that provides a wrapper around binary PED (also known as BED) files, one of the genotype/phenotype file formats of PLINK, the whole genome association analysis toolset. BEDMatrix objects are created in R by simply providing the path to a BED file and once created, they behave similarly to regular matrices with the advantage that genotypes are retrieved on demand without loading the entire file into memory. This allows handling of very large files with limited use of memory. Technically, a BEDMatrix is a memory-mapped matrix backed by a binary PED file.

This package is deliberately kept simple. For computational methods that use BEDMatrix check out the BGData package.

This example uses a very simple BED file that is bundled with this R package. It was generated from the PLINK files in the inst/extdata folder using plink --file example --make-bed --out example.

To get the path to the example BED file (system.file finds the full file names of files in packages and is only used to find the example data):

To wrap the example BED file in a BEDMatrix object:

> m <- BEDMatrix(path)
Extracting number of individuals and rownames from FAM file...
Extracting number of markers and colnames from BIM file...

To get the dimensions of the BEDMatrix object:

> dim(m)
[1] 6 3

To extract a subset of the BEDMatrix object:

> m[1:3, ]
    snp1_G snp2_1 snp3_A
1_1      2      0      0
1_2      0     NA      1
1_3     NA      1      1

To get the current released version from CRAN:


To get the current development version from GitHub:


Further documentation can be found on RDocumentation.


BEDMatrix 1.3.0

  • Speed up character subsetting.
  • Speed up detection of n, p, rownames, and colnames during initialization if data.table package is installed.
  • Support str function.

BEDMatrix 1.2.0

  • Support path without extension (like PLINK).
  • Add path attribute (to reattach instance after saving it to RData).
  • Add length method.
  • Add as.matrix method.
  • Add is.matrix method.
  • Store dimensions in S3 wrapper as dims attribute to allow for faster recreation when saved.
  • Fix bug that modified i and j when subsetting.

BEDMatrix 1.1.0

  • Restore cross-platform compatibility by dropping the system dependency on Boost.IOStreams in favor of Boost.Interprocess which provides header-only memory-mapping and is therefore supported by the BH package.

BEDMatrix 1.0.1

  • Ensure that the same C compiler and compiler flags are used in the configure tests as when compiling R.
  • Improve messages in configure script to distinguish between Boost headers and Boost libraries.

BEDMatrix 1.0.0

Initial release.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


1.4.0 by Alexander Grueneberg, 19 days ago


Report a bug at https://github.com/QuantGen/BEDMatrix/issues

Browse source code at https://github.com/cran/BEDMatrix

Authors: Alexander Grueneberg [aut, cre], Lian Lian [ctb], Gustavo de los Campos [ctb]

Documentation:   PDF Manual  

MIT + file LICENSE license

Imports methods, Rcpp, crochet

Suggests data.table, testthat

Linking to Rcpp, BH

System requirements: C++11

Depended on by BGData.

Suggested by symDMatrix.

See at CRAN