-
Notifications
You must be signed in to change notification settings - Fork 3
add create_config()
function for yaml file creation
#164
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
base: who_epiverse
Are you sure you want to change the base?
Conversation
…ssing distribution name placeholder.
… and path invisibly for piping
create_config()
function for yaml file creation
…ot current directory
- Refined test for config file structure to reflect updated template - Added checks for top-level keys: `data`, `disease_name`, `severity` - Updated severity section expectations (e.g., added `epidist`) - Included assertions for NA placeholders at correct levels - Minor comments and formatting improvements for clarity
@Karim-Mane can you check the new changes . |
#' create_config("my_config.yaml") | ||
#' | ||
#' @note | ||
#' - Replace `NA` with appropriate values before using the configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#' - Replace `NA` with appropriate values before using the configuration. | |
#' - Users need to replaces `NA` with appropriate values before using the configuration. |
total_cases = NA_real_, | ||
total_deaths = NA_real_, | ||
death_in_confirmed = NA_real_, | ||
account_for_delay = TRUE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This argument is redundant - so could be removed.
# "Linux" = system(paste("xdg-open", shQuote(path)), wait = FALSE) | ||
# ) | ||
|
||
if (Sys.info()["sysname"] == "Darwin") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the switch instead of if statement. It has an else option that you can use to specify instruction for other conditions.
#' Load Configuration Parameters | ||
#' | ||
#' @param path Path to config file (default: tempdir()/config.yaml) | ||
#' @return List with loaded data and parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#' @return List with loaded data and parameters | |
#' @returns List with loaded data and parameters |
total_death <- NULL | ||
|
||
# Load data if path provided | ||
if (!is.na(config$data)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!is.na(config$data)) { | |
if (!is.na(config[["data"]])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace all occurrences of $
with [[""]]
.
stop("Data file not found: ", config$data) | ||
} | ||
|
||
ext <- tools::file_ext(config$data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to check for file extension. We will use {rio} for data import.
|
||
# Validate mutual exclusivity | ||
if (!is.null(data) && (!is.null(total_count) || !is.null(total_death))) { | ||
stop("Configuration conflict: Provide either data OR counts, not both") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stop("Configuration conflict: Provide either data OR counts, not both") | |
stop("Configuration conflict: Provide either the data path OR the count of total cases and deaths, not both") |
total_death <- severity$total_deaths %||% NULL | ||
|
||
# Validate mutual exclusivity | ||
if (!is.null(data) && (!is.null(total_count) || !is.null(total_death))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use {checkmate} for this validation
stop("Configuration conflict: Provide either data OR counts, not both") | ||
} | ||
|
||
if (is.null(data) && (is.null(total_count) || is.null(total_death))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try use {checkmate} here too.
stop("Must provide either data file or both total_cases/total_deaths") | ||
} | ||
|
||
list( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use a return()
function
This PR is the config creation function for the pipeline:
Improved User Experience:
Code Quality:
yaml::write_yaml()
invisible(path)
)user interaction:
Enhanced Documentation:
Validation & Safety: