Skip to content
Snippets Groups Projects
Select Git revision
  • f5f396fd5e76351b884a390f2b535c227a02d813
  • master default protected
  • 40-joss-submission
  • 91-add_pkgdown_github_page
  • bugfix
  • 92-bugfixes_test_pipeline_jobn
  • 90-add_fun_install_ogs
  • 76-check_platform_compatibility
  • 85-add_win_runner
  • v.0.4.652
  • v0.4.644
  • v0.4.643
  • v0.4.642
  • v0.3.641
  • v0.2
  • 0.1.0
16 results

utils.R

Blame
  • 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,