setMetaValue: Set Meta Value (generic)

Description Usage Arguments Path-like identifiers Author(s) References See Also Examples

Description

Sets meta value inside the respective environment for meta information.

Usage

1
2
3
4
5
setMetaValue(id, value, where = tryCatch(devtools::as.package(".")$package,
  error = function(cond) {     stop("Invalid default value for `where`") }),
  sub_id = character(), fail_value = NULL, force = FALSE, gap = TRUE,
  must_exist = FALSE, reactive = FALSE, return_status = TRUE,
  strict = c(0, 1, 2), typed = FALSE, ...)

Arguments

id

Signature argument. Object containing path-like ID information.

value

Signature argument. Object containing value information.

where

Signature argument. Object containing information about the location of the option container that is to be used. Typically, this either corresponds to the name/ID of a package/package project or an instance of a custom class for which suitable methods in the context of managing options are defined (see other methods of this package that have signature arguments id or where).

sub_id

character. Optional ID for a sub layer. Useful for a hub-like option container structure.

fail_value

ANY. Value that is returned if assignment failed and return_status = FALSE.

force

logical. TRUE: when dirname(id) points to a leaf instead of a branch (i.e. dirname(id) is not an environment), overwrite it to turn it into a branch and vice versa when id points to a branch that is to be transformed into a leaf; FALSE: either return with fail_value or signal condition depending on value of strict.

gap

logical. TRUE: when dirname(id) points to a non-existing parent branch or if there are any missing branches in the nested structure, then auto-create all missing branches; FALSE: either return with fail_value or throw a condition in such cases (depending on strict);

must_exist

logical. TRUE: id pointing to a non-existing meta object either results in return value fail_value or signal a condition depending on strict; FALSE: meta object that id points to is set.

reactive

logical. TRUE: set reactive meta object via setShinyReactive. FALSE: set regular/non-reactive meta object value. Note that if value inherits from ReactiveExpression (which it does if reactiveExpression or wrappers around this function are used), reactive is automatically set to TRUE.

return_status

logical. TRUE: return status (TRUE for successful assignment, FALSE for failed assignment); FALSE: return actual assignment value (value) or fail_value.

strict

logical. Controls what happens when id points to a non-existing meta object:

  • 0: ignore and return FALSE to signal that the assignment process was not successful or fail_value depending on the value of return_status

  • 1: ignore and with warning and return FALSE

  • 2: ignore and with error

typed

logical. TRUE: create an implicitly typed meta object; FALSE: create a regular meta object.

Further

arguments to be passed along to subsequent functions. In particular: setShinyReactive.

Path-like identifiers

Values for id are expected to be of structure a/b/c/.../z, i.e. path-like identifiers using a slash as separator. The identifier is transformed to a$b$c$...$z and then in turn to a valid get or assign expression (i.e. something similar to getOptionContainer(...)$a$b$c$...$z and getOptionContainer(...)$a$b$c$...$z <- value). Of course, "atomic" paths (e.g. only a) are also valid.

Author(s)

Janko Thyson janko.thyson@gmail.com

References

http://github.com/Rappster/optionr

See Also

setMetaValue-char-any-char-method, getMetaValue, existsMetaValue, rmMetaValue

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## Not run: 

##------------------------------------------------------------------------------
## Default location of option container //
##------------------------------------------------------------------------------

## NOTE
## Obmitting `where` (and `id` in `initializeOptionContainer()`) in the all 
## calls will assign the overall option container to the package/project 
## name (if `hidden = TRUE` it is additionally prepended by a `.`)

initializeOptionContainer(overwrite = TRUE)
setMetaValue(id = "x_1", value = 10)
getMetaValue(id = "x_1")

##------------------------------------------------------------------------------
## Explicit location of option container //
##------------------------------------------------------------------------------

initializeOptionContainer(id = "test", overwrite = TRUE)
setMetaValue(id = "x_1", value = 10, where = "test")
getMetaValue(id = "x_1", where = "test")

##------------------------------------------------------------------------------
## Sub ID //
##------------------------------------------------------------------------------

initializeOptionContainer(sub_id = "a", overwrite = TRUE)
setMetaValue(id = "x_1", value = 10, sub_id = "a")
getMetaValue(id = "x_1", sub_id = "a")


## End(Not run)

rappster/optionr documentation built on May 26, 2019, 11:23 p.m.