From bffe052208289d8a120c9ac6bee02768c89f1ab7 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 18 Apr 2024 18:00:43 +0200 Subject: [PATCH] perf(app): #182 move directory creation later Move directory creation to just prior to writing the first file to output directory, so that it is not created unnecessarily. Closes: #182 --- run_pacta_data_preparation.R | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/run_pacta_data_preparation.R b/run_pacta_data_preparation.R index 78e10c6..a84a77d 100644 --- a/run_pacta_data_preparation.R +++ b/run_pacta_data_preparation.R @@ -81,15 +81,6 @@ config[["data_prep_outputs_path"]] <- file.path( paste(config[["pacta_financial_timestamp"]], system_timestamp, sep = "_") ) -if (dir.exists(config[["data_prep_outputs_path"]])) { - logger::log_warn("POTENTIAL DATA LOSS: Output directory already exists, and files may be overwritten ({config[[\"data_prep_outputs_path\"]]}).") - warning("Output directory exists. Files may be overwritten.") -} else { - logger::log_trace("Creating output directory: \"{config[[\"data_prep_outputs_path\"]]}\"") - dir.create(config[["data_prep_outputs_path"]], recursive = TRUE) -} - - # input filepaths -------------------------------------------------------------- masterdata_ownership_path <- @@ -300,6 +291,16 @@ saveRDS(currencies, currencies_data_path) logger::log_info("Saving file: \"index_regions.rds\".") saveRDS(index_regions, index_regions_data_path) +# Create output directory --------------------------------------------------------- + +if (dir.exists(config[["data_prep_outputs_path"]])) { + logger::log_warn("POTENTIAL DATA LOSS: Output directory already exists, and files may be overwritten ({config[[\"data_prep_outputs_path\"]]}).") + warning("Output directory exists. Files may be overwritten.") +} else { + logger::log_trace("Creating output directory: \"{config[[\"data_prep_outputs_path\"]]}\"") + dir.create(config[["data_prep_outputs_path"]], recursive = TRUE) +} + # financial data output --------------------------------------------------------