From 9ba41a9fd79d60fca867a085504fc974a8bfbef6 Mon Sep 17 00:00:00 2001 From: Jacob Kastl <60064070+jacobvjk@users.noreply.github.com> Date: Mon, 23 Sep 2024 12:21:40 +0200 Subject: [PATCH] use prepared abcd in matching (#153) * use prepared abcd in matching * Update R/run_match_prioritize.R Co-authored-by: CJ Yetman * Update R/run_matching.R Co-authored-by: CJ Yetman --------- Co-authored-by: CJ Yetman --- R/run_match_prioritize.R | 15 ++++++++++----- R/run_matching.R | 17 ++++++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/R/run_match_prioritize.R b/R/run_match_prioritize.R index f5d6efdc..d84b3fdd 100644 --- a/R/run_match_prioritize.R +++ b/R/run_match_prioritize.R @@ -2,8 +2,7 @@ run_match_prioritize <- function(config) { config <- load_config(config) dir_matched <- get_matched_dir(config) - path_abcd <- get_abcd_path(config) - sheet_abcd <- get_abcd_sheet(config) + abcd_dir <- get_abcd_dir(config) match_prio_priority <- get_match_priority(config) @@ -11,6 +10,10 @@ run_match_prioritize <- function(config) { sector_split_type_select <- get_sector_split_type(config) # validate config values---- + stop_if_not_length(abcd_dir, 1L) + stop_if_not_inherits(abcd_dir, "character") + stop_if_dir_not_found(abcd_dir, desc = "ABCD data") + stop_if_file_not_found(file.path(abcd_dir, "abcd_final.csv"), desc = "ABCD final") stop_if_not_length(dir_matched, 1L) stop_if_not_inherits(dir_matched, "character") stop_if_dir_not_found(dir_matched, desc = "Matched loanbook") @@ -62,9 +65,11 @@ run_match_prioritize <- function(config) { col_select = dplyr::all_of(col_select_companies_sector_split) ) - # TODO: better use prepared abcd? - abcd <- read_abcd_raw(path_abcd, sheet_abcd) - stop_if_not_expected_columns(abcd, cols_abcd, desc = "ABCD") + abcd <- readr::read_csv( + file.path(abcd_dir, "abcd_final.csv"), + col_select = dplyr::all_of(cols_abcd), + col_types = col_types_abcd_final + ) } # prioritize and save files---- diff --git a/R/run_matching.R b/R/run_matching.R index a569d31b..5ad48741 100644 --- a/R/run_matching.R +++ b/R/run_matching.R @@ -2,8 +2,7 @@ run_matching <- function(config) { config <- load_config(config) dir_raw <- get_raw_dir(config) - path_abcd <- get_abcd_path(config) - sheet_abcd <- get_abcd_sheet(config) + abcd_dir <- get_abcd_dir(config) dir_matched <- get_matched_dir(config) matching_by_sector <- get_match_by_sector(config) @@ -23,9 +22,10 @@ run_matching <- function(config) { stop_if_not_inherits(dir_raw, "character") stop_if_dir_not_found(dir_raw, desc = "Raw loanbook") - stop_if_not_length(path_abcd, 1L) - stop_if_not_inherits(path_abcd, "character") - stop_if_file_not_found(path_abcd, desc = "ABCD data") + stop_if_not_length(abcd_dir, 1L) + stop_if_not_inherits(abcd_dir, "character") + stop_if_dir_not_found(abcd_dir, desc = "ABCD data") + stop_if_file_not_found(file.path(abcd_dir, "abcd_final.csv"), desc = "ABCD final") stop_if_not_length(dir_matched, 1L) stop_if_not_inherits(dir_matched, "character") @@ -64,8 +64,11 @@ run_matching <- function(config) { # load data---- ## load abcd---- - abcd <- read_abcd_raw(path_abcd, sheet_abcd) - stop_if_not_expected_columns(abcd, cols_abcd, desc = "ABCD") + abcd <- readr::read_csv( + file.path(abcd_dir, "abcd_final.csv"), + col_select = dplyr::all_of(cols_abcd), + col_types = col_types_abcd_final + ) ## optionally load manual classification system---- if (matching_use_manual_sector_classification) {