R/check_snp.R

Defines functions check_snp

Documented in check_snp

#' Checks that the `snp` is valid
#'
#' Checks that the `snp` is valid.
#' Calls \link{stop} if not
#' @inheritParams default_params_doc
#' @return nothing
#' @examples
#' check_snp("rs1234")
#' @author Richèl J.C. Bilderbeek
#' @export
check_snp <- function(snp) {
  if (length(snp) != 1) {
    stop(
      "'snp' must be one string. \n",
      "length(snp): ", length(snp)
    )
  }
  pattern <- "^([[:alnum:]]|_)+$"
  if (
    !stringr::str_detect(
      string = snp,
      pattern = pattern
    )
  ) {
    stop(
      "'snp' must match regex '", pattern, "' \n",
      "snp: ", snp
    )
  }
}
richelbilderbeek/plinkr documentation built on March 25, 2024, 3:18 p.m.