-
Notifications
You must be signed in to change notification settings - Fork 0
HTNPoRT changes #31
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
Merged
Merged
HTNPoRT changes #31
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ae61c29
added support for logistic regression
yulric 2f9ed27
fixed bug with missing column centereredVariableType in center file
yulric 43d5817
Fixed error in DESCRIPTION file
yulric 31ce85e
fixed bug in validate_model_parameter_file where the files referenced…
yulric 4308e5d
Updated return of the validate_model_parameter_file
yulric 7861977
updated description for the name column in the coefficients files to …
yulric 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
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,125 @@ | ||
| #' Creates a folder with model parameter files for testing purposes. The folder | ||
| #' is cleaned up after the test is done. | ||
| #' | ||
| #' @param model_parameter_files a named list containing all the model parameter | ||
| #' files to add to the folder. Each name in the list should be name of the file | ||
| #' including its extension and each value should be a data frame that contains | ||
| #' the file's contents. The named list must contain an entry for the model | ||
| #' export file which should be named `model-export.csv`. | ||
| #' @param env DO NOT SET THIS. Optional parameter that used for clean up | ||
| #' purposes | ||
| #' @return a string containing the path to the model export file | ||
| #' @examples | ||
| #' \dontrun { | ||
| #' model_export_file <- data.frame( | ||
| #' fileType = c("model-steps"), | ||
| #' filePath = c("./model-steps.csv") | ||
| #' ) | ||
| #' model_steps_file <- data.frame( | ||
| #' step = c("dummy"), | ||
| #' fileType = c("N/A"), | ||
| #' filePath = c("./dummy.csv"), | ||
| #' notes = c("") | ||
| #' ) | ||
| #' dummy_file <- data.frame( | ||
| #' origVar = c("sex"), | ||
| #' catValue = c("1"), | ||
| #' dummyVariable = c("sex_cat1") | ||
| #' ) | ||
| #' | ||
| #' model_export_file_path <- .create_model_parameters_test_dir(list( | ||
| #' "model-export.csv" = model_export_file, | ||
| #' "model-steps.csv" = model_steps_file, | ||
| #' "dummy.csv" = dummy_file | ||
| #' )) | ||
| #' } | ||
| .create_model_parameters_test_dir <- function( | ||
| model_parameter_files, env = parent.frame()) { | ||
| MODEL_EXPORT_FILE_NAME <- "model-export.csv" | ||
|
|
||
| stopifnot(MODEL_EXPORT_FILE_NAME %in% names(model_parameter_files)) | ||
|
|
||
| MODEL_PARAMETERS_FOLDER_NAME <- "model-parameters" | ||
| model_parameters_folder_path <- file.path( | ||
| tempdir(), MODEL_PARAMETERS_FOLDER_NAME) | ||
| dir.create(model_parameters_folder_path) | ||
| withr::defer(unlink(model_parameters_folder_path, recursive = TRUE), env) | ||
|
|
||
| for(file_name in names(model_parameter_files)) { | ||
| current_file <- model_parameter_files[[file_name]] | ||
| write.csv(current_file, file.path(model_parameters_folder_path, file_name)) | ||
| } | ||
|
|
||
| return(file.path(model_parameters_folder_path, MODEL_EXPORT_FILE_NAME)) | ||
| } | ||
|
|
||
| test_that("files within the model steps file should be validated", { | ||
| model_export_file <- data.frame( | ||
| fileType = c("model-steps"), | ||
| filePath = c("./model-steps.csv") | ||
| ) | ||
| model_steps_file <- data.frame( | ||
| step = c("dummy"), | ||
| fileType = c("N/A"), | ||
| filePath = c("./dummy.csv"), | ||
| notes = c("") | ||
| ) | ||
| dummy_file <- data.frame( | ||
| origVar = c("sex"), | ||
| catValue = c("1"), | ||
| dummyVariable = c("sex_cat1") | ||
| ) | ||
|
|
||
| model_export_file_path <- .create_model_parameters_test_dir(list( | ||
| "model-export.csv" = model_export_file, | ||
| "model-steps.csv" = model_steps_file, | ||
| "dummy.csv" = dummy_file | ||
| )) | ||
|
|
||
| expected_result <- list( | ||
| success = FALSE, | ||
| errors = c( | ||
| "Column <origVariable> not found in file dummy.csv" | ||
| ) | ||
| ) | ||
|
|
||
| actual_result <- validate_model_parameters(model_export_file_path) | ||
|
|
||
| expect_equal(actual_result, expected_result) | ||
| }) | ||
|
|
||
| test_that("files within model steps whose type is in the fileType column should | ||
| be validated", { | ||
| model_export_file <- data.frame( | ||
| fileType = c("model-steps"), | ||
| filePath = c("./model-steps.csv") | ||
| ) | ||
| model_steps_file <- data.frame( | ||
| step = c("fine-and-gray"), | ||
| fileType = c("beta-coefficients"), | ||
| filePath = c("./beta-coefficients.csv"), | ||
| notes = c("") | ||
| ) | ||
| beta_coefficients <- data.frame( | ||
| var = c("sex_cat1"), | ||
| type = c("cat"), | ||
| coefficient = c("2") | ||
| ) | ||
|
|
||
| model_export_file_path <- .create_model_parameters_test_dir(list( | ||
| "model-export.csv" = model_export_file, | ||
| "model-steps.csv" = model_steps_file, | ||
| "beta-coefficients.csv" = beta_coefficients | ||
| )) | ||
|
|
||
| expected_result <- list( | ||
| success = FALSE, | ||
| errors = c( | ||
| "Column <variable> not found in file beta-coefficients.csv" | ||
| ) | ||
| ) | ||
|
|
||
| actual_result <- validate_model_parameters(model_export_file_path) | ||
|
|
||
| expect_equal(actual_result, expected_result) | ||
| }) |
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.
Uh oh!
There was an error while loading. Please reload this page.