R: Produce a function which can get or set global options

setGlobalOptions {GlobalOptions} | R Documentation

## Produce a function which can get or set global options

### Description

Produce a function which can get or set global options

### Usage

    setGlobalOptions(..., get_opt_value_fun = FALSE)

### Arguments

`...` | specification of options, see 'details' section
`get_opt_value_fun` | whether return a `get_opt_value` function as well

### Details

The most simple way is to construct an option function (e.g. `foo.options()`) as:

        foo.options = setGlobalOptions(
            "a" = 1,
            "b" = "text"
        )

Then users can get or set the options by

        foo.options()
        foo.options("a")
        foo.options$a
        foo.options(c("a", "b"))
        foo.options("a", "b")
        foo.options("a" = 2)
        foo.options$a = 2
        foo.options("a" = 2, "b" = "new_text")

Options can be reset to their default values by:

        foo.options(RESET = TRUE)

The value for each option can be set as a list which contains more controls of the option:

        foo.options = setGlobalOptions(
            "a" = list(.value = 1,
                       .length = 1,
                       .class = "numeric",
                       .validate = function(x) x > 0)
        )

The different fields in the list can be used to filter or validate the option values.

`.value`

  The default value.

`.length`

  The valid length of the option value. It can be a vector, the check will be passed if one of the length fits.

`.class`

  The valid class of the option value. It can be a vector, the check will be passed if one of the classes fits.

`.validate`

  Validation function. The input parameter is the option value and should return a single logical value.

`.failed_msg`

  Once validation failed, the error message that is printed.

`.filter`

  Filtering function. The input parameter is the option value and it should return a filtered option value.

`.read.only`

  Logical. The option value can not be modified if it is set to `TRUE`.

`.visible`

  Logical. Whether the option is visible to users.

`.private`

  Logical. The option value can only be modified in the same namespace where the option function is created.

`.synonymous`

  a single option name which should have been already defined ahead of current option. The option specified will be shared by current option.

For more detailed explanation, please go to the vignette.

### Author(s)

Zuguang Gu <z.gu@dkfz.de>

### Examples

    # please go to the vignette

[Package GlobalOptions version 0.0.12 Index]