R/option.R

#' option
#'
#' Processes a simple option or a key value pairs of options separated by commas.
#'
#' @param opts character: simple option or a key value pairs of options 
#'
#' @return nothing
#' @export
#' @md 
#'
#' @examples
#' # simple option
#' opt <- option("run")
#' opt
#' # key-value options
#' opt <- option("int=2,text=hello,boolean=T")
#' opt
option <- function (opts) {
  expr <- parse(text=paste0("list(", opts, ")"))
  vars <- all.vars(expr)
  env  <- new.env()
  if (length(vars)) {
    for (i in 1:length(vars)) env[[vars[i]]] <- vars[i]
  }
  eval(expr, env)
}
sigbertklinke/extpro documentation built on Dec. 31, 2020, 7:26 a.m.