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.

Travis-CI Build Status CRAN_Status_Badge Rdoc

BEDMatrix is an R package that provides a matrix-like wrapper around .bed, 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.

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


This example uses a dummy .bed file that is bundled with this R package. It was generated using plink --dummy 500 1000 0.02 acgt --seed 4711 --out example with PLINK 1.90 beta 3.452.

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 samples and rownames from FAM file...
Extracting number of variants and colnames from BIM file...

To get the dimensions of the BEDMatrix object:

> dim(m)
[1] 50 1000

To extract a subset of the BEDMatrix object:

> m[1:3, 1:5]
          snp0_A snp1_C snp2_G snp3_G snp4_G
per0_per0      0      1      1      1      0
per1_per1      1      1      1      1     NA
per2_per2      1      0      0      2      0


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

  • Support subsetting by NA.
  • Use crochet package for subsetting
  • Fix minor subsetting bugs
  • Update example
  • Remove intermediate S3 BEDMatrix type

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, a year 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 popkin, symDMatrix.

See at CRAN