R/transform_template_load.R

Defines functions transform_template_load

Documented in transform_template_load

#' @title Trasformation of the load template
#' 
#' @description This function will transform the load template in order to fill all empty and necessary cells.
#' 
#' @author Briac LE RAY (briac.leray@partnre.com)
#' 
#' @return The dataframe modified.
#' @param input_load_table The table with the loading template format. Type = dataframe
#' @examples transform_template_load(input_table = my_template_filled)

transform_template_load = function(input_load_table) {
  
  # Remove trailing and leading spaces
  input_load_table[] = lapply(input_load_table, trimws)
  
  # Add column interesting_as_is
  input_load_table = input_load_table %>% mutate(interesting_as_is = ifelse(str_detect(string = Nom_de_la_table_source, pattern = " |-") |
                                                                              str_detect(string = Nom_du_champ_source, pattern = " |-") |
                                                                              is.na(Nom_de_la_table_source) |
                                                                              is.na(Nom_du_champ_source),
                                                                            FALSE,
                                                                            TRUE))
  
  # Fill Nom_du_champ if the cells used to be merged
  input_load_table = input_load_table %>% fill(Nom_du_champ)
  
  # # Remove spaces in Nom_du_champ_source
  # input_load_table = input_load_table %>% mutate(Nom_du_champ_source = str_replace_all(string = Nom_du_champ_source, pattern = " ", replacement = ""))
  
  return(input_load_table)
}
Tiipiac/StressTestOptimization documentation built on Dec. 18, 2021, 5:08 p.m.