R/match_intrnl.R

Defines functions decode_intrnl match_intrnl

match_intrnl <- function(x, table_nom, ux = NULL) {
  if (is.raw(x)) {
    # idempotent
    return(x)
  }
  if (is.null(ux)) {
    ux <- get_dhhs(table_nom)
  }
  if (is.null(ux)) {
    stop("`ux` was NULL.")
  }
  m <- fmatch(x, ux)
  if (length(ux) < 255 && !anyNA(m)) {
    as.raw(m)
  } else {
    m
  }
}

decode_intrnl <- function(x, table_nom, ux = NULL) {
  if (is.null(ux)) {
    ux <- get_dhhs(table_nom)
  }
  if (!is.integer(x)) {
    ux[as.integer(x)]
  } else {
    ux[x]
  }
}
HughParsonage/dhhs documentation built on Dec. 17, 2021, 11:22 p.m.