R/bfile.R

Defines functions bfile

#' @title Create BED, BIM, FAM Variables
#'
#' @description Convenience function to create the variables .bed, .bim, .fam in the global environment to be used by other functions.
#'
#' @param filestub Stub of the PLINK bfiles.
#' @param clear Logical. Should existing bfile objects be cleared first?
#'
#' @export

bfile <- function(filestub, clear = FALSE) {
  if(clear) {
    rm(.bed, .bim, .fam, .bfile, envir = .GlobalEnv)
    return(invisible(NULL))
  }

  bfile <- filestub
  class(bfile) <- "bfile"

  assign(".bed", paste0(filestub, ".bed"), envir=.GlobalEnv)
  assign(".bim", paste0(filestub, ".bim"), envir=.GlobalEnv)
  assign(".fam", paste0(filestub, ".fam"), envir=.GlobalEnv)
  assign(".bfile", bfile, envir=.GlobalEnv)

}
mattwarkentin/genetools documentation built on Nov. 4, 2019, 6:19 p.m.