Skip to content
Snippets Groups Projects
Commit c0d79b43 authored by Ruben Heinrich's avatar Ruben Heinrich
Browse files

[base] Improved get_obj_status

parent 74bbda4b
No related branches found
No related tags found
1 merge request!6Merge branch 7 fixed functionality into master
...@@ -181,60 +181,56 @@ get_implemented_classes <- function(){ ...@@ -181,60 +181,56 @@ get_implemented_classes <- function(){
#===== INFO UTILITY ===== #===== INFO UTILITY =====
#'get_list_status #'get_obj_status
#'@description Helper function for get_status() to check if a list has at least #'@description Helper function for get_status() to check the status of an OGS6
#' one element. #' parameter
#'@param flag Boolean flag to keep track of missing components #'@param flag flag: To keep track of missing components
#'@param obj_list The specified list #'@param obj OGS6 parameter: Either a wrapper list or an r2ogs6 class object
#'@param element_type Optional: What kind of elements are in the list? get_obj_status <- function(flag, obj){
#'@param is_opt flag: Does the list need at least one element?
get_list_status <- function(flag, assertthat::assert_that(assertthat::is.flag(flag))
obj_list,
element_type = "list element", ogs6_parameter_name <- unlist(strsplit(deparse(substitute(obj)),
is_opt = FALSE){ ".",
fixed = TRUE))[[2]]
sim_ready <- flag
is_optional <- is_optional_sim_component(ogs6_parameter_name)
if(length(obj_list) == 0){
if(!is_opt){ if(is.null(obj) || length(obj) == 0){
cat(crayon::red("\u2717")) if(!is_optional){
sim_ready <- FALSE cat(crayon::red("\u2717\t"))
flag <- FALSE
}else{ }else{
cat(crayon::yellow("()")) cat(crayon::yellow("()\t"))
} }
}else{ }else{
cat(crayon::green("\u2713")) cat(crayon::green("\u2713\t"))
} }
cat(" At least one", element_type, "was defined", "\n") # Check if parameter is r2ogs6 class object or wrapper list
if(any(grepl("r2ogs6_", class(obj), fixed = TRUE))){
cat("OGS6$", ogs6_parameter_name, " is defined\n", sep = "")
}else{
cat("OGS6$", ogs6_parameter_name, " has at least one element\n", sep = "")
}
return(invisible(sim_ready)) return(invisible(flag))
} }
#'obj_is_defined #'is_optional_sim_component
#'@description Helper function for get_status() to check if an object was #'@description Checks if a simulation component is optional
#' defined #'@param ogs6_parameter_name string: Name of a OGS6 parameter
#'@param flag Boolean flag to keep track of missing components is_optional_sim_component <- function(ogs6_parameter_name){
#'@param obj The specified object
#'@param obj_type Optional: What kind of object is this?
#'@param is_opt flag: Is the element optional i.e. can it be NULL?
obj_is_defined <- function(flag,
obj,
obj_type = "",
is_opt = FALSE){
is_defined <- flag
if(is.null(obj)){
cat(crayon::red("\u2717"))
is_defined <- FALSE
}else{
cat(crayon::green("\u2713"))
}
cat(" ", obj_type, "object is not NULL", "\n") optional_sim_components <- c("gml",
"local_coordinate_system",
"curves",
"search_length_algorithm",
"test_definition",
"insitu")
return(invisible(is_defined)) return(invisible(ogs6_parameter_name %in% optional_sim_components))
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment