R/ukb_info.R

Defines functions ukb_info

Documented in ukb_info

#' A tools4ukbb function
#' Function output: output of the dx_date, dx_age, and dx_hx functions (either subsetted or attached to the original phenotype dataframe)
#' 
#' @param icd_list a list of the icd10 codes you wish to investigate
#' @param dataframe the originial phenotype dataframe containing all individuals in the ukbiobank (~500,000 cols x 18,000 rows as of 09/07/2021)
#' @param disease_name a string containing the name of the disease(s) of interest
#' @param requested the columns requested. Strings containing "date" will call the dx_date function; "age", the dx_age function; and, "hx", the  dx_hx function. 
#' Therefore, "datehx", "dataandhx" and "date_hx" will all call the dx_date and dx_age functions.
#' @param combined this column indicates if you would like to recieve the requested column(s) joined with the whole phenotype dataframe (TRUE) or the subsetted, dx_positive, dataframe (FALSE)
#' @keywords info
#' @export
#' @examples
#' ukb_info()

ukb_info <- function(icd_list, dataframe, disease_name) {
  indiv_with_disease <- individuals_with_disease(icd_list, dataframe)
  dx_positive<- filter(dataframe, is_in(eid, indiv_with_disease[[1]]))   
  
  eid_df <- select(dx_positive, eid)
    date_dx <- dx_date(icd_list, disease_name, dataframe) %>% left_join(eid_df, by ="eid")
    age_dx  <- dx_age(icd_list, disease_name, dataframe) %>% left_join(eid_df, by ="eid")
  
    hx_dx <- dx_hx(icd_list, disease_name, dataframe) %>% left_join(eid_df, by ="eid")
  
  date_age <- left_join(date_dx, age_dx) 
  hx_date_age <- left_join(date_age, hx_dx)
  final  <- hx_date_age[,colSums(is.na(hx_date_age))<nrow(hx_date_age)]
  final
  
}
Lab-Jaiswal/tools4ukbb documentation built on May 12, 2022, 9:11 a.m.