R/extract_simple_dependencies.R

Defines functions extract_simple_dependencies

Documented in extract_simple_dependencies

#' #' Extract simple dependencies.
#'
#' @param this_data The tibble to be checked for missing data.
#' @param this_glossary The glossary dictionary with parameter visit/test battery etc information.
#' @param id_var A quosure representing the column that contains the patient label.
#' @param site_var A quosure representing the column that contains the site name for that patient.
#' @param these_dependencies A dependencies object (likely generated by parse_MACRO_DSD_file_for_glossary_and_dependencies()).
#'
#' @importFrom dplyr pull
#' @importFrom dplyr filter
#' @importFrom dplyr bind_rows
#' @importFrom dplyr mutate
#' @importFrom dplyr mutate_all
#' @importFrom dplyr %>%
#' @importFrom rlang .data
#'
#' @return Missing data percentages in a tibble
#' @export
extract_simple_dependencies = function( this_data,
                                        this_glossary,
                                        id_var,
                                        site_var,
                                        these_dependencies ) {

  patient_list     = this_data %>% pull( !!id_var ) %>% unique %>% as.character

  expected_columns = these_dependencies %>%
    filter( .data$param_dependencies=="NA" ) %>%
    filter( .data$param_dependencies_manual == "NA" ) %>%
    pull( .data$column_name )

  expected_data.raw = this_data %>%
    mutate_all( as.character ) %>%
    select( !!id_var, !!site_var, !!expected_columns ) %>%
    pivot_longer( -c({{id_var}}, {{site_var}}),
                  names_to  = "column_name",
                  values_to = "value" ) %>%
    mutate( value = na_if( .data$value, "" ) )


  return( expected_data.raw )
}
LisaHopcroft/CTutils documentation built on Oct. 7, 2021, 11:08 p.m.