-
Notifications
You must be signed in to change notification settings - Fork 0
Implement comprehensive three-tier validation system for Excel imports #194
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
Open
nautilus69
wants to merge
7
commits into
main
Choose a base branch
from
ValidateImportFiles
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1e80209
Implement comprehensive three-tier validation system for Excel imports
85e13c9
Fixing the pkgdown error
2fe7385
Merge branch 'main' into ValidateImportFiles
AKostiv8 b030f52
Refactor: Extract validation to esqlabsR and config-driven dropdowns
AKostiv8 182afa4
attach validation from esqlabsR@extending-validation
AKostiv8 7689595
Improve validation error display with detailed file-specific messages
nautilus69 fa81a70
Update NEWS.md
AKostiv8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,197 @@ | ||
| #' Dropdown Population Utilities | ||
| #' | ||
| #' @description Configuration-driven system for populating dropdown menus | ||
| #' from imported Excel data. Eliminates repetitive code and makes dropdown | ||
| #' dependencies explicit. | ||
|
|
||
| #' Populate Dropdowns from Configuration | ||
| #' | ||
| #' @description Populates dropdown options based on a configuration map. | ||
| #' Automatically handles file existence checks, null checks, and data extraction. | ||
| #' | ||
| #' @param dropdowns The DROPDOWNS reactive values object to populate | ||
| #' @param data The r$data object containing imported configuration data | ||
| #' @param config A list defining dropdown mappings (see examples) | ||
| #' | ||
| #' @return NULL (modifies dropdowns in place) | ||
| #' | ||
| #' @examples | ||
| #' \dontrun{ | ||
| #' config <- list( | ||
| #' scenarios = list( | ||
| #' individual_id = list( | ||
| #' file = "individuals", | ||
| #' sheet = "IndividualBiometrics", | ||
| #' column = "IndividualId" | ||
| #' ) | ||
| #' ) | ||
| #' ) | ||
| #' populate_dropdowns(DROPDOWNS, r$data, config) | ||
| #' } | ||
| #' | ||
| #' @export | ||
| populate_dropdowns <- function(dropdowns, data, config) { | ||
| for (dropdown_group in names(config)) { | ||
| for (dropdown_name in names(config[[dropdown_group]])) { | ||
| dropdown_spec <- config[[dropdown_group]][[dropdown_name]] | ||
|
|
||
| # Extract specification | ||
| file_name <- dropdown_spec$file | ||
| sheet_name <- dropdown_spec$sheet | ||
| column_name <- dropdown_spec$column | ||
| extract_type <- dropdown_spec$extract # e.g., "sheets", "unique" | ||
| transform <- dropdown_spec$transform # Optional transformation function | ||
|
|
||
| # Check if file exists | ||
| file_path <- data[[file_name]]$file_path | ||
| if (is.null(file_path) || is.na(file_path) || !file.exists(file_path)) { | ||
| next | ||
| } | ||
|
|
||
| # Handle different extraction types | ||
| if (!is.null(extract_type)) { | ||
| if (extract_type == "sheets") { | ||
| # Extract sheet names | ||
| dropdowns[[dropdown_group]][[dropdown_name]] <- data[[file_name]]$sheets | ||
| } | ||
| } else if (!is.null(sheet_name) && !is.null(column_name)) { | ||
| # Extract column from sheet | ||
| sheet_data <- data[[file_name]][[sheet_name]] | ||
| if (is.null(sheet_data) || is.null(sheet_data$modified)) { | ||
| next | ||
| } | ||
|
|
||
| column_data <- sheet_data$modified[[column_name]] | ||
| if (is.null(column_data)) { | ||
| next | ||
| } | ||
|
|
||
| # Apply transformation if specified | ||
| if (!is.null(transform)) { | ||
| column_data <- transform(column_data) | ||
| } else { | ||
| # Default: get unique values | ||
| column_data <- unique(column_data) | ||
| } | ||
|
|
||
| dropdowns[[dropdown_group]][[dropdown_name]] <- column_data | ||
| } | ||
| } | ||
| } | ||
|
|
||
| invisible(NULL) | ||
| } | ||
|
|
||
| #' Create Named List Transformation | ||
| #' | ||
| #' @description Helper function to create a named list transformation for dropdowns | ||
| #' | ||
| #' @param names_col The column to use as names | ||
| #' @param values_col The column to use as values | ||
| #' | ||
| #' @return A transformation function | ||
| #' | ||
| #' @export | ||
| named_list_transform <- function(names_col, values_col) { | ||
| function(data) { | ||
| setNames( | ||
| as.list(as.character(data[[values_col]])), | ||
| data[[names_col]] | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| #' Get Default Dropdown Configuration | ||
| #' | ||
| #' @description Returns the default dropdown configuration for the application. | ||
| #' This configuration defines which dropdowns pull data from which files/sheets/columns. | ||
| #' | ||
| #' @return A list defining dropdown mappings | ||
| #' | ||
| #' @export | ||
| get_dropdown_config <- function() { | ||
| list( | ||
| scenarios = list( | ||
| individual_id = list( | ||
| file = "individuals", | ||
| sheet = "IndividualBiometrics", | ||
| column = "IndividualId" | ||
| ), | ||
| population_id = list( | ||
| file = "populations", | ||
| sheet = "Demographics", | ||
| column = "PopulationName" | ||
| ), | ||
| outputpath_id = list( | ||
| file = "scenarios", | ||
| sheet = "OutputPaths", | ||
| column = "OutputPathId" | ||
| ), | ||
| model_parameters = list( | ||
| file = "models", | ||
| extract = "sheets" | ||
| ) | ||
| ), | ||
| plots = list( | ||
| path_options = list( | ||
| file = "scenarios", | ||
| sheet = "OutputPaths", | ||
| column = "OutputPath" | ||
| ), | ||
| scenario_options = list( | ||
| file = "scenarios", | ||
| sheet = "Scenarios", | ||
| column = "Scenario_name" | ||
| ), | ||
| datacombinedname_options = list( | ||
| file = "plots", | ||
| sheet = "DataCombined", | ||
| column = "DataCombinedName" | ||
| ), | ||
| plotgridnames_options = list( | ||
| file = "plots", | ||
| sheet = "plotGrids", | ||
| column = "name" | ||
| ), | ||
| plotids_options = list( | ||
| file = "plots", | ||
| sheet = "plotConfiguration", | ||
| column = "plotID" | ||
| ) | ||
| ), | ||
| applications = list( | ||
| application_protocols = list( | ||
| file = "applications", | ||
| extract = "sheets" | ||
| ) | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| #' Populate Special Dropdowns | ||
| #' | ||
| #' @description Handles special dropdown cases that don't fit the standard pattern | ||
| #' (e.g., outputpath_id_alias which creates a named list) | ||
| #' | ||
| #' @param dropdowns The DROPDOWNS reactive values object to populate | ||
| #' @param data The r$data object containing imported configuration data | ||
| #' | ||
| #' @return NULL (modifies dropdowns in place) | ||
| #' | ||
| #' @export | ||
| populate_special_dropdowns <- function(dropdowns, data) { | ||
| # Handle outputpath_id_alias (named list mapping) | ||
| if (!is.null(data$scenarios$OutputPaths) && | ||
| !is.null(data$scenarios$OutputPaths$modified)) { | ||
| output_paths <- data$scenarios$OutputPaths$modified | ||
|
|
||
| if (!is.null(output_paths$OutputPathId) && !is.null(output_paths$OutputPath)) { | ||
| dropdowns$scenarios$outputpath_id_alias <- setNames( | ||
| as.list(as.character(output_paths$OutputPath)), | ||
| output_paths$OutputPathId | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| invisible(NULL) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Please rephrase to "validate loaded project" - as we plan to move away from the excel structure.