R/algs-checker.R

Defines functions source_dir find_methods

Documented in find_methods source_dir

#' Read algorithms
#'
#' @description
#' Function reads optimization algorithms to current environment from
#' specified directory by YAML-config or from default directory.
#'
#' @param .dir directory with R source code of methods :: string
#' @export

source_dir = function(.dir = "./Algs") {
  files =
    base::list.files(path = .dir, full.names = TRUE)
  files %>%
    purrr::map(base::source)
}

#' Check availability of method
#'
#' @description
#' Function checks if specified by YAML-config algorithms are available.
#'
#' @param .funcs  functions :: [function]
#' @export

find_methods = function(.funcs) {
  .funcs %>%
    purrr::map(function(func) {
                 if(func %in% ls(envir = .GlobalEnv)) {
                   cli::cli_div(theme = list(span.emph = list(color = "green")))
                   cli::cli_alert_success("Algorithm {.emph {func}} is available.")
                 }
                 else {
                   cli::cli_div(theme = list(span.emph = list(color = "red")))
                   cli::cli_alert_danger("There is no algorithm {.emph {func}} in specified directory!")
                 }
       })
}
warbarbye/cecs-benchmark documentation built on March 10, 2020, 12:09 a.m.