R/labelValue.R

Defines functions labelValue

Documented in labelValue

#' Gets strings for code values
#'
#' Returns the string labels for the building codes
#' @param v variable name
#' @param i code values present
#' @return labels
#' @export
#' @examples
#' labelValue(v,i)

labelValue <- function(v, i, flag) {
	if (flag == "building") {
		bldg_code_lbl <- read.csv("/Users/bradleywilson/dev/nepal/building_code_labels.csv",
		                           header = TRUE, sep = ",")
		if (grepl("sup_str",v) == TRUE) {
			v <- "sup_str"
		}
		else if (grepl("gersk_ls",v) == TRUE) {
			v <- "gersk_ls"
		}
		else if (grepl("secuse_ls",v) == TRUE) {
			v <- "secuse_ls"
		}
		ind <- which(bldg_code_lbl$variable %in% v & bldg_code_lbl$code_val %in% i)
		labs <- as.character(bldg_code_lbl$val_label)[ind]
		return(labs)
	}

	if (flag == "household") {
		house_code_lbl <- read.csv("/Users/bradleywilson/dev/nepal/household_labels.csv",
		                           header = TRUE, sep = ",")

		ind <- which(house_code_lbl$variable %in% v & house_code_lbl$code_val %in% i)
		labs <- as.character(house_code_lbl$val_label)[ind]
		return(labs)
	}
}
bradleyswilson/hrrp documentation built on May 28, 2019, 7:13 p.m.