Skip to content

Consider creating a function to access configuration values #474

Description

@ocaisa

Right now we use things like

`r config$remote$prompt` module list

but this just returns NULL when the configuration variable does not exist (i.e., it does not error).

I wonder if we are not better off creating a helper function where we do some error control:

get_config <- function(..., default = '', required = TRUE) {
  path <- list(...)
  value <- config

  for (name in path) {
    if (!is.list(value) || is.null(value[[name]])) {
      if (!required) return(default)
      stop(
        sprintf("Missing configuration value: %s", paste(path, collapse = "$")),
        call. = FALSE
      )
    }
    value <- value[[name]]
  }
  value
}

which could have usage like

`r get_config("remote", "prompt")` module list

This would also open the door to incremental improvement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions