R/bcsi_to_npers.R

Defines functions bcsi_to_npers

Documented in bcsi_to_npers

#' Transforming BCSI_ID to N_PERS
#'
#' @details rstats version of the excel calculation =(A32*100)+ (97-((A32-INT(A32/97)*97)))
#'
#' @param bcsi A BCSI_ID to transform to N_PERS
#'
#' @return A character string with 10 digit N_PERS
#' @import stringr
#' @export
#'
#' @examples
#' bcsi_to_npers(00392498)
#' bcsi_to_npers(392498)



bcsi_to_npers <- function(bcsi) {

  if(anyNA(as.numeric(bcsi))) {
    warning("bcsi contains non-numeric characters")
  }


  bcsi <- as.numeric(bcsi)
  npers <- (bcsi*100) + (97-(bcsi - (bcsi %/% 97)*97))
  npers <- stringr::str_pad(npers, side = "left", width = 10, pad = "0")
  return(npers)
}
suzanbaert/kycdata documentation built on May 23, 2019, 6:08 p.m.