write_fam: Write Plink *.fam files

Description Usage Arguments Value See Also Examples

View source: R/write_fam.R

Description

This function writes a tibble with the right columns into a standard Plink *.fam file. It uses readr::write_tsv() to do it efficiently.

Usage

1
write_fam(file, tib, verbose = TRUE)

Arguments

file

Output file (whatever is accepted by readr::write_tsv()). If file is missing the expected *.fam extension, the function adds it.

tib

The tibble or data.frame to write. It must contain these columns: fam, id, pat, mat, sex, pheno. Throws an error if any of these columns are missing. Additional columns are ignored. Columns are automatically reordered in output as expected in format.

verbose

If TRUE (default), function reports the path of the file being written (after autocompleting the extension).

Value

The output tib invisibly (what readr::write_tsv() returns).

See Also

write_plink() for writing a set of BED/BIM/FAM files.

Plink FAM format reference: https://www.cog-genomics.org/plink/1.9/formats#fam

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# to write an existing table `fam` into file "data.fam", run like this:
# write_fam("data", fam)
# this also works
# write_fam("data.fam", fam)

# The following example is more detailed but also more awkward
# because (only for these examples) the package must create the file in a *temporary* location

# create a dummy tibble with the right columns
library(tibble)
tib <- tibble(
    fam = 1:3,
    id = 1:3,
    pat = 0,
    mat = 0,
    sex = 1,
    pheno = 1
)
# a dummy file
file_out <- tempfile('delete-me-example', fileext = '.fam') # will also work without extension
# write the table out in *.fam format (no header, columns in right order)
write_fam(file_out, tib)
# delete output when done
file.remove(file_out)

genio documentation built on June 11, 2021, 5:12 p.m.