Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

align variable names (and related function and parameter names) #226

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions R/analyse.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,32 @@
analyse <- function(config) {
config <- load_config(config)

output_analysis_dir <- get_output_analysis_dir(config)
dir_analysis <- get_dir_analysis(config)

stop_if_not_length(output_analysis_dir, 1L)
stop_if_not_inherits(output_analysis_dir, "character")
stop_if_not_length(dir_analysis, 1L)
stop_if_not_inherits(dir_analysis, "character")

if (dir.exists(output_analysis_dir)) {
if (dir.exists(dir_analysis)) {
ask_for_permission(
"The output directory defined by the {.var dir_analysis} parameter in your config already exists.\n
{.path {output_analysis_dir}}\n
{.path {dir_analysis}}\n
Would you like to delete it and replace it with the output of the current run?"
)
unlink(output_analysis_dir, recursive = TRUE)
unlink(dir_analysis, recursive = TRUE)
}
dir.create(output_analysis_dir, recursive = TRUE, showWarnings = FALSE)
dir.create(dir_analysis, recursive = TRUE, showWarnings = FALSE)

run_pacta(config)
run_aggregate_alignment_metric(config)
plot_aggregate_loanbooks(config)

write_manifest(
config = config,
path = file.path(output_analysis_dir, "manifest.yml"),
path = file.path(dir_analysis, "manifest.yml"),
prior_input_paths = c(
get_output_prepare_dir(config),
get_output_matched_loanbooks_dir(config),
get_output_prio_diagnostics_dir(config)
get_dir_prepared_abcd(config),
get_dir_matched_loanbooks(config),
get_dir_prioritized_loanbooks_and_diagnostics(config)
)
)
}
Expand Down
56 changes: 28 additions & 28 deletions R/load_config.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,46 @@ load_config <- function(config) {
config
}

get_input_dir <- function(params) {
get_dir_input <- function(params) {
params[["directories"]][["dir_input"]]
}

get_loanbook_dir <- function(params) {
get_dir_loanbooks <- function(params) {
file.path(
params[["directories"]][["dir_input"]],
"loanbooks"
)
}

get_abcd_filename <- function(params) {
get_filename_abcd <- function(params) {
params[["file_names"]][["filename_abcd"]]
}

get_abcd_sheet <- function(params) {
get_sheet_abcd <- function(params) {
params[["file_names"]][["sheet_abcd"]]
}

get_output_prepare_dir <- function(params) {
get_dir_prepared_abcd <- function(params) {
params[["directories"]][["dir_prepared_abcd"]]
}

get_output_matched_loanbooks_dir <- function(params) {
get_dir_matched_loanbooks <- function(params) {
params[["directories"]][["dir_matched_loanbooks"]]
}

get_output_prio_diagnostics_dir <- function(params) {
get_dir_prioritized_loanbooks_and_diagnostics <- function(params) {
params[["directories"]][["dir_prioritized_loanbooks_and_diagnostics"]]
}

get_output_analysis_dir <- function(params) {
get_dir_analysis <- function(params) {
params[["directories"]][["dir_analysis"]]
}

get_scenario_tms_filename <- function(params) {
get_filename_scenario_tms <- function(params) {
params[["file_names"]][["filename_scenario_tms"]]
}

get_scenario_sda_filename <- function(params) {
get_filename_scenario_sda <- function(params) {
params[["file_names"]][["filename_scenario_sda"]]
}

Expand Down Expand Up @@ -130,52 +130,52 @@ get_use_manual_sector_classification <- function(params) {
params[["matching"]][["manual_sector_classification"]][["use_manual_sector_classification"]]
}

get_manual_sector_classification_filename <- function(params) {
get_filename_manual_sector_classification <- function(params) {
params[["matching"]][["manual_sector_classification"]][["filename_manual_sector_classification"]]
}

get_manual_sector_classification_path <- function(params) {
get_path_manual_sector_classification <- function(params) {
file.path(
get_input_dir(params),
get_manual_sector_classification_filename(params)
get_dir_input(params),
get_filename_manual_sector_classification(params)
)
}

get_abcd_path <- function(config) {
get_path_abcd <- function(config) {
file.path(
get_input_dir(config),
get_abcd_filename(config)
get_dir_input(config),
get_filename_abcd(config)
)
}

get_sector_split_path <- function(config) {
get_path_sector_split <- function(config) {
file.path(
get_input_dir(config),
get_dir_input(config),
config[["sector_split"]][["filename_split_company_id"]]
)
}

get_advanced_company_indicators_path <- function(config) {
get_path_advanced_company_indicators <- function(config) {
file.path(
get_input_dir(config),
get_dir_input(config),
config[["sector_split"]][["filename_advanced_company_indicators"]]
)
}

get_advanced_company_indicators_sheet <- function(config) {
get_sheet_advanced_company_indicators <- function(config) {
config[["sector_split"]][["sheet_advanced_company_indicators"]]
}

get_scenario_tms_path <- function(config) {
get_path_scenario_tms <- function(config) {
file.path(
get_input_dir(config),
get_scenario_tms_filename(config)
get_dir_input(config),
get_filename_scenario_tms(config)
)
}

get_scenario_sda_path <- function(config) {
get_path_scenario_sda <- function(config) {
file.path(
get_input_dir(config),
get_scenario_sda_filename(config)
get_dir_input(config),
get_filename_scenario_sda(config)
)
}
54 changes: 27 additions & 27 deletions R/match_loanbooks.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ match_loanbooks <- function(config) {
config <- load_config(config)

# input paths for match_loanbooks
input_loanbooks_dir <- get_loanbook_dir(config)
output_prepare_dir <- get_output_prepare_dir(config)
dir_loanbooks <- get_dir_loanbooks(config)
dir_prepared_abcd <- get_dir_prepared_abcd(config)

# output path for match_loanbooks
output_matched_loanbooks_dir <- get_output_matched_loanbooks_dir(config)
dir_matched_loanbooks <- get_dir_matched_loanbooks(config)

if (dir.exists(output_matched_loanbooks_dir)) {
if (dir.exists(dir_matched_loanbooks)) {
ask_for_permission(
"The output directory defined by the {.var dir_matched_loanbooks} parameter in your config already exists.\n
{.path {output_matched_loanbooks_dir}}\n
{.path {dir_matched_loanbooks}}\n
Would you like to delete it and replace it with the output of the current run?"
)
unlink(output_matched_loanbooks_dir, recursive = TRUE)
unlink(dir_matched_loanbooks, recursive = TRUE)
}
dir.create(output_matched_loanbooks_dir, recursive = TRUE, showWarnings = FALSE)
dir.create(dir_matched_loanbooks, recursive = TRUE, showWarnings = FALSE)

matching_by_sector <- get_match_by_sector(config)
matching_min_score <- get_match_min_score(config)
Expand All @@ -47,22 +47,22 @@ match_loanbooks <- function(config) {

matching_use_manual_sector_classification <- get_use_manual_sector_classification(config)
if (matching_use_manual_sector_classification) {
path_manual_sector_classification <- get_manual_sector_classification_path(config)
path_manual_sector_classification <- get_path_manual_sector_classification(config)
}

# validate config values----
stop_if_not_length(input_loanbooks_dir, 1L)
stop_if_not_inherits(input_loanbooks_dir, "character")
stop_if_dir_not_found(input_loanbooks_dir, desc = "Input - loanbooks")
stop_if_not_length(dir_loanbooks, 1L)
stop_if_not_inherits(dir_loanbooks, "character")
stop_if_dir_not_found(dir_loanbooks, desc = "Input - loanbooks")

stop_if_not_length(output_prepare_dir, 1L)
stop_if_not_inherits(output_prepare_dir, "character")
stop_if_dir_not_found(output_prepare_dir, desc = "Output - prepare ABCD")
stop_if_file_not_found(file.path(output_prepare_dir, "abcd_final.csv"), desc = "ABCD final")
stop_if_not_length(dir_prepared_abcd, 1L)
stop_if_not_inherits(dir_prepared_abcd, "character")
stop_if_dir_not_found(dir_prepared_abcd, desc = "Output - prepare ABCD")
stop_if_file_not_found(file.path(dir_prepared_abcd, "abcd_final.csv"), desc = "ABCD final")

stop_if_not_length(output_matched_loanbooks_dir, 1L)
stop_if_not_inherits(output_matched_loanbooks_dir, "character")
stop_if_dir_not_found(output_matched_loanbooks_dir, desc = "Output - Matched loanbooks")
stop_if_not_length(dir_matched_loanbooks, 1L)
stop_if_not_inherits(dir_matched_loanbooks, "character")
stop_if_dir_not_found(dir_matched_loanbooks, desc = "Output - Matched loanbooks")

stop_if_not_length(matching_by_sector, 1L)
stop_if_not_inherits(matching_by_sector, "logical")
Expand Down Expand Up @@ -98,7 +98,7 @@ match_loanbooks <- function(config) {

## load abcd----
abcd <- readr::read_csv(
file.path(output_prepare_dir, "abcd_final.csv"),
file.path(dir_prepared_abcd, "abcd_final.csv"),
col_select = dplyr::all_of(cols_abcd),
col_types = col_types_abcd_final
)
Expand All @@ -113,11 +113,11 @@ match_loanbooks <- function(config) {
}

## load raw loan books----
list_raw <- list.files(path = input_loanbooks_dir, pattern = "[.]csv$")
stop_if_no_files_found(list_raw, input_loanbooks_dir, "dir_input", "raw loan book CSVs")
list_raw <- list.files(path = dir_loanbooks, pattern = "[.]csv$")
stop_if_no_files_found(list_raw, dir_loanbooks, "dir_input", "raw loan book CSVs")

raw_lbk <- readr::read_csv(
file = file.path(input_loanbooks_dir, list_raw),
file = file.path(dir_loanbooks, list_raw),
col_types = col_types_raw,
id = "group_id"
) %>%
Expand Down Expand Up @@ -167,17 +167,17 @@ match_loanbooks <- function(config) {
## write matched data to file----
matched_lbk_i %>%
readr::write_csv(
file = file.path(output_matched_loanbooks_dir, glue::glue("matched_lbk_{group_name}.csv")),
file = file.path(dir_matched_loanbooks, glue::glue("matched_lbk_{group_name}.csv")),
na = ""
)
cli::cli_progress_update()
}

cli::cli_progress_done()

write_manifest(
config = config,
path = file.path(output_matched_loanbooks_dir, "manifest.yml"),
prior_input_paths = c(output_prepare_dir)
path = file.path(dir_matched_loanbooks, "manifest.yml"),
prior_input_paths = c(dir_prepared_abcd)
)
}
Loading