R/drug_fixer.epiinfo.R

Defines functions drug_fixer.epiinfo

Documented in drug_fixer.epiinfo

#' Fix EpiInfo drug dosing data
#'
#' Take data frame with drug dosing variables and output 
#' binary factorised variables 
#' @param x data frame containing outcome variables
#' @param ... further arguments passed to or from other methods
#' @author Jay Achar \email{jay.achar@@doctors.org.uk}
#' @seealso \code{\link{tbcleanr}}
#' @importFrom purrr map_at
#' @export 

drug_fixer.epiinfo <- function(x, ...) {
    
    # check drug variables correct based on set arg
    drugs <- c("HDH","RDR", "EDE", "ZDZ", "SDS",
           "KADKA", "OFLDOFL", "CAPDCAP", "ETHDETH", "CYCLDCYCL", "AMXDAMX", "PASDPAS",
           "CLADCLA", "CLODCLO", "LXDLX", "MXDMX", "PTDPT", "LZDDLZD", "IMPDIMP",
           "BDQDBDQ", "DLMDDLM")
    
    # convert all variables to numerical for yn_binary_fixer()
    x[] <- map_at(x, .at = drugs, .f = as.numeric)
    
    # recode drug variables 
    x[] <- map_at(x, .at = drugs, .f = yn_binary_fixer)
    
x    
}
JayAchar/tbcleanr documentation built on Aug. 12, 2020, 8:40 a.m.