Skip to content

Commit

Permalink
swapped ifelse to dedicated function
Browse files Browse the repository at this point in the history
  • Loading branch information
natemcintosh committed Dec 13, 2024
1 parent af863f2 commit 87d4cd3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
16 changes: 3 additions & 13 deletions R/pipeline.R
Original file line number Diff line number Diff line change
Expand Up @@ -215,26 +215,16 @@ execute_model_logic <- function(config, output_dir, blob_storage_container) {
metadata <- list(
job_id = config@job_id,
task_id = config@task_id,
data_path = ifelse(
# is_empty checks for NULL and empty data structures
rlang::is_empty(config@data@path),
"", config@data@path
),
data_path = empty_str_if_non_existant(config@data@path),
model = config@model,
disease = config@disease,
geo_value = config@geo_value,
report_date = config@report_date,
production_date = config@production_date,
max_reference_date = config@max_reference_date,
min_reference_date = config@min_reference_date,
exclusions = ifelse(
rlang::is_empty(config@exclusions@path),
"", config@exclusions@path
),
blob_storage_container = ifelse(
rlang::is_empty(blob_storage_container),
"", blob_storage_container
),
exclusions = empty_str_if_non_existant(config@exclusions@path),
blob_storage_container = empty_str_if_non_existant(blob_storage_container),
run_at = format(Sys.time(), "%Y-%m-%dT%H:%M:%S%z")
)

Expand Down
5 changes: 5 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ check_file_exists <- function(data_path) {
}
invisible(data_path)
}

#' If `x` is null or empty, return an empty string, otherwise `x`
empty_str_if_non_existant <- function(x) {
ifelse(rlang::is_empty(x), "", x)
}

0 comments on commit 87d4cd3

Please sign in to comment.