Skip to content

Commit

Permalink
use prepared abcd in matching (#153)
Browse files Browse the repository at this point in the history
* use prepared abcd in matching

* Update R/run_match_prioritize.R

Co-authored-by: CJ Yetman <[email protected]>

* Update R/run_matching.R

Co-authored-by: CJ Yetman <[email protected]>

---------

Co-authored-by: CJ Yetman <[email protected]>
  • Loading branch information
jacobvjk and cjyetman authored Sep 23, 2024
1 parent 3795acb commit 9ba41a9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
15 changes: 10 additions & 5 deletions R/run_match_prioritize.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ 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)

apply_sector_split <- get_apply_sector_split(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")
Expand Down Expand Up @@ -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----
Expand Down
17 changes: 10 additions & 7 deletions R/run_matching.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9ba41a9

Please sign in to comment.