R/select_columns.R

Defines functions select_columns

Documented in select_columns

#' @title Find necessary columns
#' 
#' @description This function selects the columns necessary from a dataframe.
#' 
#' @author Briac LE RAY (briac.leray@partnre.com)
#' 
#' @return The list of the columns mentionned in the templates. Type = dataframe
#' @param template_load_data The filled loading template. Type = dataframe
#' @param template_merge The filled merging template. Type = dataframe
#' @examples select_columns(template_load_data = my_filled_template, template_merge = my_filled_template)

select_columns <- function(template_load_data, template_merge) {
  columns_attributes = data.frame(table_source = character(), attributes = character())
  
  # For the data source template :
  columns_attributes = bind_rows(columns_attributes,
                                 get_columns_attributes_template_data(template_load_data %>% filter(interesting_as_is == TRUE)))
  
  # For the merge template :
  columns_attributes = bind_rows(columns_attributes,
                                 get_columns_attributes_template_merge(template_merge))
  
  columns_attributes = columns_attributes %>% 
    distinct() %>%
    group_by(table_source) %>%
    summarise(attributes = paste(attributes, sep = "", collapse = ", "))
  
  return(columns_attributes)
}
Tiipiac/StressTestOptimization documentation built on Dec. 18, 2021, 5:08 p.m.