R/get_columns_attributes_template_merge.R

Defines functions get_columns_attributes_template_merge

Documented in get_columns_attributes_template_merge

#' @title Retrieve attributes
#' 
#' @description Goes through the template merge data to retrieve all the attributes mentionned.
#' 
#' @author Briac LE RAY (briac.leray@partnre.com)
#' 
#' @return A dataframe containing the names of the tables and the names of the attributes.
#' @param template_merge The filled template. Type = dataframe
#' @examples get_columns_attributes_template_data(template_merge = my_filled_template)


get_columns_attributes_template_merge <- function(template_merge) {
  columns_attributes = data.frame(table_source = character(), attributes = character())
  
  for (row in 1:nrow(template_merge)) {
    line = template_merge[row,]
    
    for (attribute in str_split(string = line[["Attributs_de_la_table_x"]], pattern = ",")) {
      columns_attributes = bind_rows(columns_attributes,
                                     data.frame(table_source = line[["Nom_de_la_table_x"]], attributes = attribute))
    }
    for (attribute in str_split(string = line[["Attributs_de_la_table_y"]], pattern = ",")) {
      columns_attributes = bind_rows(columns_attributes,
                                     data.frame(table_source = line[["Nom_de_la_table_y"]], attributes = attribute))
    }
  }
  
  return(distinct(columns_attributes))
}
Tiipiac/StressTestOptimization documentation built on Dec. 18, 2021, 5:08 p.m.