R/map_medications.R

Defines functions map_medications

Documented in map_medications

#' Map medications
#' Last updated: 2020-06-21
#'
#' @param drug_name A string
#' @param medications_file A string
#' @param remove_vaccines A binary value
#' @return A tibble \code{medications}
#' @export

map_medications <- function(drug_name, medications_file, remove_vaccines = TRUE) {

  medications <- read_csv(medications_file, col_types=cols())
  names(medications) <- tolower(names(medications))
  medications <- inner_join(
    medications,
    rxcui2in,
    by = 'rxcui'
  )
  #remove vaccines, because there are many false-positive correlations
  if (remove_vaccines == TRUE) {
    medications <- medications %>%
      filter(!(str_detect(rxcui_ingr_name, "vaccine")))
  }
  #remove columns that do not add information
  medications <- medications %>%
    select(person_id, date, rxcui_ingr)

  return(medications)
}
patrickwu510/ddiwas documentation built on June 26, 2020, 6:56 a.m.