The goal of {plink2} is to provide an R thin wrapper around
PLINK2 binaries.
# install.packages("pak")
pak::pak("patterninstitute/plink2"){plink2} detects the binary build automatically when you run
plink2(). It will download the right build binary the first time.
Run the binary plink2 via the R function plink2():
library(plink2)
# plink version
version()
#> [1] "PLINK v2.0.0-a.6.9LM AVX2 AMD (29 Jan 2025)"# Equivalent to running plink2 in the terminal.
plink2()
#> PLINK v2.0.0-a.6.9LM AVX2 AMD (29 Jan 2025) cog-genomics.org/plink/2.0/
#> (C) 2005-2025 Shaun Purcell, Christopher Chang GNU General Public License v3
#>
#> plink2 <input flag(s)...> [command flag(s)...] [other flag(s)...]
#> plink2 --help [flag name(s)...]
#>
#> Commands include --rm-dup list, --make-bpgen, --export, --freq, --geno-counts,
#> --sample-counts, --missing, --hardy, --het, --fst, --indep-pairwise,
#> --r2-phased, --sample-diff, --make-king, --king-cutoff, --pmerge, --pgen-diff,
#> --check-sex, --write-samples, --write-snplist, --make-grm-list, --pca, --glm,
#> --adjust-file, --gwas-ssf, --pheno-svd, --clump, --score-list, --variant-score,
#> --genotyping-rate, --pgen-info, --validate, and --zst-decompress.
#>
#> "plink2 --help | more" describes all functions.Arguments that would be passed in the terminal like --help, can be
passed to plink2()’s R function like:
# Pass `TRUE` for the full help.
# Equivalent to `plink2 --help` in the terminal.
# plink2(help = TRUE)
# Equivalent to `plink2 --help merge` in the terminal.
plink2(help = "merge")
#> PLINK v2.0.0-a.6.9LM AVX2 AMD (29 Jan 2025) cog-genomics.org/plink/2.0/
#> (C) 2005-2025 Shaun Purcell, Christopher Chang GNU General Public License v3
#>
#> --pmerge <.pgen/.bed filename> <.pvar/.bim> <.psam/.fam>
#> --pmerge <.pgen + .pvar + .psam fileset prefix> ['vzs']
#> Merge the given fileset with the initially loaded fileset, writing the
#> result to <output prefix>.pgen + .pvar + .psam.
#> --pmerge-list <filename> [mode]
#> Merge all filesets named in the text file. Also merge with the initially
#> loaded fileset if one was specified.
#> When a line in the text file contains three entries, they are interpreted
#> as full filenames for a binary fileset (.pgen/.bed, then .pvar/.bim, then
#> .psam/.fam). If it contains exactly one entry, its interpretation depends
#> on the mode:
#> * 'bfile': Prefix for .bed + .bim + .fam fileset.
#> * 'bpfile': Prefix for .pgen + .bim + .fam fileset.
#> * 'pfile' (default): Prefix for .pgen + .pvar + .psam fileset.
#> * 'pfile-vzs': Prefix for .pgen + .pvar.zst + .psam fileset.
#> For both --pmerge and --pmerge-list:
#> * All input filesets must be sorted by position, and have the same
#> chromosome order. (When this isn't true, use --make-pgen + --sort-vars
#> on each fileset first.)
#> * Variants are only merged if their IDs AND positions match. (This is a
#> change from PLINK 1.x.)