R/getRefcodes.R

Defines functions getRefcodes

Documented in getRefcodes

#' @rdname internal_desc
#' @export
getRefcodes <- function(xvar){
  ## DESCRIPTION: Internal function to facilitate looking at codes from ref_codes
  ##		If xvar does not exist, returns NULL
  ## ARGUMENTS:
  ## xvar - The name of the variable.
  ## VALUE: The table name


  vardiff <- c("FORTYPCD", "FLDTYPCD", "FORTYPGRP", "FORTYPCDCALC", "TYPGRPCD",
	paste0("DSTRBCD", seq(1:3)), paste0("TRTCD", seq(1:3)))

  if (!xvar %in% vardiff) {
    if (grepl("PREV_", xvar)) {
      xvar <- sub("PREV_", "", xvar)
    }
    if (!xvar %in% FIESTAutils::ref_codes[["VARIABLE"]]) {
      return(NULL)
    }
  } else {

    switch(xvar,
      FORTYPCD = 'FORTYPCD',
      FLDTYPCD = 'FORTYPCD',
      FORTYPGRP = 'FORTYPCD',
      FLDTYPGRP = 'FORTYPCD',
      FORTYPCDCALC = 'FORTYPCD',
      TYPGRPCD = 'FORTYPCD',
      DSTRBCD1 = 'DSTRBCD',
      DSTRBCD2 = 'DSTRBCD',
      DSTRBCD3 = 'DSTRBCD',
      TRTCD1 = 'TRTCD',
      TRTCD2 = 'TRTCD',
      TRTCD3 = 'TRTCD',
    )
  }
  return(FIESTAutils::ref_codes[FIESTAutils::ref_codes$VARIABLE == xvar,
		c("VALUE", "MEANING", "GROUPCD", "GROUPNM")])

}

Try the FIESTAutils package in your browser

Any scripts or data that you put into this service are public.

FIESTAutils documentation built on May 29, 2024, 4:06 a.m.