Select Git revision
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
utils.R 17.11 KiB
#This script contains some useful methods for a developer.
#===== IMPLEMENTATION UTILITY =====
#'select_fitting_subclass
#'@description Utility function to differentiate which property class to pick
#' i.e. when dealing with r2ogs6 which has 3 subclasses with the tag name
#' 'property'
#'@param xpath_expr string: An XPath expression
#'@param subclasses_names character: A named character vector
select_fitting_subclass <- function(xpath_expr, subclasses_names){
assertthat::assert_that(assertthat::is.string(xpath_expr))
assertthat::assert_that(is.character(subclasses_names))
split_path <- unlist(strsplit(xpath_expr, "/", fixed = TRUE))
# If name of subclass tag is unique
if(length(subclasses_names[names(subclasses_names) ==
split_path[[length(split_path)]]]) == 1){
tag_name <- split_path[[length(split_path)]]
return(invisible(subclasses_names[[tag_name]]))
}
grandparent_path <- paste(utils::tail(split_path, 3), collapse = "/")
subclass_name <- ""
switch(
grandparent_path,
"medium/phases/phase" =
{
subclass_name <- "r2ogs6_phase"
},
"medium/properties/property" =
{
subclass_name <- "r2ogs6_pr_property"
},
"phase/properties/property" =
{
subclass_name <- "r2ogs6_ph_property"
},
"component/properties/property" =
{
subclass_name <- "r2ogs6_com_property"
}
)
return(invisible(subclass_name))
}
#'get_subclass_names
#'@description Utility function, returns the names of the subclasses
#' of a r2ogs6 class
#'@param class_name string: The name of a r2ogs6 class
#'@return character: The names of the subclasses as a character vector
#' (empty if there are none)
get_subclass_names <- function(class_name) {
assertthat::assert_that(assertthat::is.string(class_name))
subclasses_names <- character()
switch(class_name,